If Range("condition_cell".Value = Range("test_cell".Value Then
Do_This 'subroutine - see below
Else
Do_That 'subroutine - see below
End If
End Sub
Sub Do_This()
Application.Goto Application.Range("B20"
ActiveCell = "This action was taken because the condition is TRUE"
End Sub
Sub Do_That()
Application.Goto Application.Range("J10"
ActiveCell = "This action was taken because the condition is FALSE"
End Sub
PLEASE NOTE: The BEST method of referring to a cell (or range of cells) in the worksheet, is to "NAME" it. This is to say, assign a "Range Name".
In the example code above, I have used two Range Names - called "test_cell", and "condition_cell". These two names have therefore been assigned to two separate cells in the worksheet.
The "easy" method of assigning a Range Name is: 1) Go to the cell (or highlight a range), 2) use Control-F3 (hold down the Control key and hit the F3 key), 3) type the name you wish to use, and 4) hit the Enter key.
IMPORTANCE OF RANGE NAMES: Range Names are EXTREMELY important - because by using them, you do NOT have to worry about always having to update your VBA code to reflect the changes which will likely occur in your worksheet as it evolves. With Range Names, Excel (internally)
"automatically" adjusts the names to reflect any changes to the worksheet.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.