Im busy trying to write code that calls different macros based on the value of a cell across an entire range on VBA.
So for the example I have a range S20:S21.
When the value in cell S20 is equal to 1, I want to call macro1. When the value in cell S21 is equal to 2, I want to call macro2.
When there is no match I have a time that it will test it in the next 5 seconds again where it will start from the top checking if cell S20 is 1 or of S20 is 2.
This is currently the code I have.
Dim TimeToRun
Sub auto_open()
Call ScheduleCopyPriceOver
End Sub
Sub ScheduleCopyPriceOver()
TimeToRun = Now + TimeValue("00:00:05")
Application.OnTime TimeToRun, "CopyPriceOver"
End Sub
Sub CopyPriceOver()
Application.ScreenUpdating = False
Number = Range("S20:S22").Value
If Number = 1 Then
Call Macro1
Call ScheduleCopyPriceOver
ElseIf Number = 2 Then
Call Macro2
Call ScheduleCopyPriceOver
Else
Call ScheduleCopyPriceOver
End If
End Sub
Sub auto_close()
On Error Resume Next
Application.OnTime TimeToRun, "CopyPriceOver", , False
End Sub