"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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,785
Messages
6,121,543
Members
449,038
Latest member
Guest1337

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
Back
Top