I have a recorded macro that I would like to run automatically when a range of cell values change (say "A1:A5"). How would I code this into VBA?
I have a recorded macro that I would like to run automatically when a range of cell values change (say "A1:A5"). How would I code this into VBA?
In your worksheet module, place the following code:
![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Column = 1 _ And Target.Row < 6 Then ' do something here End If End Sub
Would "' do something here" be the macro name? I tried this code and it didn't work.
UpdateMash1 is the name of the recorded macro. I can run the macro via a button and it works, but I can't seem to get it to run automatically when the cells are updated. I'm finally finished with this sheet (thanks to your help with the loop) but now there's a glitch. Cells with formulas that should update automatically when data is entered into cell ranges "B23:H23" won't update unless I scroll out of view of the cells or double click the cells and press enter.![]()
Private Sub Worksheet_Change2(ByVal Target As Range) Dim KeyCells KeyCells = Range("B23:H23") If Target.Address = KeyCells Then UpdateMash1 End If End Sub
![]()
Private Sub Worksheet_Change(ByVal Target As Range) If Intersect(Target, Range("B23:H23")) Is Nothing Then Exit Sub ' Run macro here End Sub
You've done it agian. Thank you Sir!!! Works perfectly. I found another trick while I was googling coding solutions for this. I used Application.ScreenUpdating to eliminate the screen flickering. Now it's like the glitch never happened. Here's the finished code.
Thanks again for all your help.![]()
Private Sub Worksheet_Change2(ByVal Target As Range) If Intersect(Target, Range("B23:H23")) Is Nothing Then Exit Sub Application.ScreenUpdating = False UpdateMash1 Application.ScreenUpdating = True End Sub
Cheers
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks