Thursday, 28 August 2014

Worksheet Event Worksheet_Activate to Hide the Blank Data Rows

Worksheet_Activate Event to Hide the Blank Data Rows with VBA Macro
Worksheet_Activate is one of the Worksheet Event , this Event occurs when the Worksheet get activated and then Macro code will Execute.

The following macro will Hide the Data Rows whose Data in C column range is either '0' or blank as given in below example.

Private Sub Worksheet_Activate()
Dim WB As Workbook
Dim WS As Worksheet
Dim X As Integer

Set WB = ThisWorkbook
Set WS = WB.Worksheets(ActiveSheet.Name)

WS.Rows("1:20").Hidden = False

For X = 1 To 20

MyVal = WS.Range("C" & X).Value
If MyVal = 0 Or MyVal = "" Then WS.Rows(X).Hidden = True

Next X
End Sub

Example :
Data before Event Occur :

Data after Event Occur :

No comments:

Post a Comment

Hi User, Thank You for Visiting My Blog. Please Post Your Feedback/Comments/Query.

Subscribe to Blog Posts by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts