Running macro depending on cell value

E

Esradekan

I want to run a macro depending on the cell value, selected from a
drop down box.

Lets say that data to select from is numbers 1 - 20
Lets say I wish to take the person from Sheets 1 - 20 accordingly


How can I do that


TIA


Esra
 
B

Bob Phillips

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "G1" '<== change to suit
Dim cell As Range

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
On Error Resume Next
Worksheets("Sheet" & .Value).Activate
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
E

Esradekan

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "G1"     '<== change to suit
Dim cell As Range

    On Error GoTo ws_exit
    Application.EnableEvents = False

    If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
        With Target
            On Error Resume Next
            Worksheets("Sheet" & .Value).Activate
        End With
    End If

ws_exit:
    Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)








- Show quoted text -

I dont understand this, but its ok, I have done it another way.

Thank you for your help. I appreciate it.

Esra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top