"If" within a macro referring a cell value

LostCause

Board Regular
Joined
Jul 13, 2006
Messages
99
Firstly, thanks for reading.

I'd like a macro that terminates if the value of a particular cell is 0

so, say Cell A1 = 0, end sub

but otherwise go to sheet2

Thanks.
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

njimack

Well-known Member
Joined
Jun 17, 2005
Messages
7,764
Code:
Sub TEST()
If Range("A1") <>0 Then
Sheets("Sheet2").Select
End If
End Sub
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Just to add to what Neil's said, you might want to prefix the particular cell range with the sheet it occupies otherwise it defaults to whatever sheet is active when the macro is run:

Code:
Sub TEST()
If Sheets("Sheet1").Range("A1") <>0 Then
Sheets("Sheet2").Select
End If
End Sub

Richard
 

LostCause

Board Regular
Joined
Jul 13, 2006
Messages
99
Code:
Sub TEST()
If Range("A1") <>0 Then
Sheets("Sheet2").Select
End If
End Sub

Thanks

That worked but I adapted it to this:

Code:
Sub TEST() 
If Range("A1") = 0 Then Exit Sub
Sheets("Sheet2").Select 
End Sub

Cheers
 

Watch MrExcel Video

Forum statistics

Threads
1,111,596
Messages
5,541,154
Members
410,543
Latest member
ExcelGlenn
Top