Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default If Worksheet is active then...


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


*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default If Worksheet is active then...

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

"Darin Kramer" wrote:


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


*** Sent via Developersdex http://www.developersdex.com ***

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default If Worksheet is active then...


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


"Darin Kramer" wrote:


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


*** Sent via Developersdex http://www.developersdex.com ***

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default If Worksheet is active then...


Pefect thanks!


*** Sent via Developersdex http://www.developersdex.com ***
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying the active worksheet to another worksheet in the same work queenmaam Excel Worksheet Functions 5 March 25th 08 06:56 PM
Basic Question - How do I return the worksheet number of the active worksheet? Regnab Excel Programming 2 May 17th 06 03:02 AM
Altering code to reference the worksheet before the active worksheet KimberlyC Excel Programming 8 March 15th 05 10:26 PM
copy active worksheet plus another worksheet Qaspec Excel Programming 1 February 2nd 05 01:51 PM
macro to apply worksheet event to active worksheet Paul Simon[_2_] Excel Programming 3 August 7th 03 02:50 AM


All times are GMT +1. The time now is 09:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"