Cell activity determing action

Troy

New Member
Joined
Apr 2, 2002
Messages
47
I am looking to write a macro so that when a user inputs items in a cell and <enter> the user will be taken to a different sheet. For example: Use enters 2 in B2 then they will be taken to Sheet2, If 3 in B2 then Sheet3, anything else entered in B2 the user would be taken to Sheet4.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
A change Event in the sheet code should do what you want. Something like

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$2" Then
If Target.Value = 2 Then Sheets("Sheet2").Activate
If Target.Value = 3 Then Sheets("Sheet3").Activate
If Target.Value >= 4 Then Sheets("Sheet4").Activate

End If

End Sub

Modify if needed
 
Upvote 0
Hi Troy

Here is another way:


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lRow As Integer
Dim strName As String

If Target.Column <> 2 Then End

   lRow = Target.Row
     If lRow > 3 Then
       Sheets("Sheet4").Select
     Else
       strName = Choose(lRow, "Sheet1", "Sheet2")
       Sheets(strName).Select
    End If
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,527
Messages
6,120,057
Members
448,940
Latest member
mdusw

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