If Worksheet is active then...

  • Thread starter Thread starter Darin Kramer
  • Start date Start date
D

Darin Kramer

HI there,

When a user runs a macro I need the macro to check which sheet he is
running it from, if it is the specified sheet then the macro should run,
if not it shouldent.

Whats wrong with my VB below...??

Thanks

D

Sub Run_or_not

Dim ws As Worksheet

With ActiveSheet
If ws.Name = "APP_D" Then
Call fix

ElseIf ws.Name = "x" Then


End If
End With
 
I would probably do something like this:

sub run_or_not()
if ActiveSheet.Name = "Sheet1" then
'your code here
else
'your alternate code here
end if
end sub

HTH - IT_Roofer
 
Put this in the ThisWorkbook code module for the workbook that contains
sheet("APP_D")

Private Sub Workbook_Open()

Dim ws As Worksheet
With ActiveSheet
If ws.Name = "APP_D" Then
Call fix
ElseIf ws.Name <> "APP_D" Then
MsgBox "Wrong Sheet"
End If
End With
End Sub
 

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

Back
Top