"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.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

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
 

Forum statistics

Threads
1,141,158
Messages
5,704,636
Members
421,360
Latest member
Rhodia

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
Top