Sunday 31 December 2017

How to validate a textbox while entering data in VBA | Data validation in VBA user forms

You can add below code on the event of textbox_keypress, textbox_enter, etc to validate the entry while user enters the data into the textbox.


Function ValidateTextboxForNumbersOnly(ByRef tb As MSForms.TextBox)
'Purpose : To validate and clear data in text box if value is not numeric
    If IsNumeric(tb.Value) = False Then tb.Value = ""
End Function

Friday 1 December 2017

How to unhide all sheets in an excel workbook / Show all sheets in one click / Unhide veryhidden sheets

Sometimes when we create larger reports in Excel, we will hide few sheets where we entered raw data or controls or calculations.

It's a tedious task to right click and unhide all the sheets one by one.

Sometimes, we will have sheets which are hidden from VBA IDE also which cannot be unhidden from Excel GUI.

You can unhide all the sheets in an excel workbook with a small piece of code below.


Sub UnHideSheets()
Dim Sht As Worksheet
For Each Sht In ThisWorkbook.Sheets
    Sht.Visible = xlSheetVisible
Next Sht
End Sub