if value = x then set sheets=y

axg275

Active Member
Joined
Oct 5, 2004
Messages
308
hello,

Just a quick question, I am trying to write a code, whith an attept to input an if statment. I am trying to write it such that on the if statement it would go to a specific sheet.

Something like

If activecell.value <=0 then

sheetsname = data

Else

sheetsname = data1

end if

sheets(sheetsname).select

Something like that, but its not working.

Thanks for your help
 

Some videos you may like

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Put the "data" and "data1" in quotes if those are the actual sheet names and not variables. For example:

Code:
Sub test()
Dim sheetsname As String

If ActiveCell.Value <= 0 Then
    sheetsname = "data"
Else
    sheetsname = "Data1"
End If

Sheets(sheetsname).Select
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,118,017
Messages
5,569,640
Members
412,284
Latest member
Daibear
Top