How to make VBA loop check excel sheet continuously

ImogenRClark

New Member
Joined
Jan 11, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi everyone :)
I'm very new to VBA and I'm trying to get my code to run continuously so that every time the excel spread sheet data is updated, it will automatically make the changes without having to manually re-run the code. Here's my code:

Sub Hide_Rows_Based_On_Cell_Value()

StartRow = 2

Dim EndRow As Long

EndRow = Range(“A:A”).SpecialCells(xlCellTypeLastCell).Row

ColNum = 7

For i = StartRow To EndRow

If Cells(i, ColNum).Value <> "Open" And Cells(i, ColNum).Value <> 0 Then

Cells(i, ColNum).EntireRow.Hidden = True

Else

Cells(i, ColNum).EntireRow.Hidden = False

End If

Next i

End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this:
add the below code to the worksheet you want the macro to be on automated on

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 7 Then
        Hide_Rows_Based_On_Cell_Value
    End If
End Sub
 
Upvote 0
Try this:
add the below code to the worksheet you want the macro to be on automated on

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 7 Then
        Hide_Rows_Based_On_Cell_Value
    End If
End Sub
That worked straight away! Thank you so much!
 
Upvote 0

Forum statistics

Threads
1,214,965
Messages
6,122,500
Members
449,090
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top