LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Junior Member
 
Posts: 1
Default select worksheet and run macro

Hi,

I am trying to run some code when a worksheet is selected.

I'm doing this using a macro currently (code below), but this requires that i use a quick menu button and i would like to make it a form button and assign a macro to it (so i can distribute the file without everyone having to create a menu button).

I would like to replace (or modify) the code below to select any sheet other than the ones named "a" and "b".

Can someone help modify this code please ?

Many thanks,

Code:
Sub ImportAlarms()
    Dim thisSheet As Worksheet
    Dim targetSheet As Worksheet
 
    On Error GoTo failed
 
    Set thisSheet = Application.ActiveSheet
    Set targetSheet = Sheets(TARGET_SHEET)
 
    If (Not (thisSheet Is Nothing) And Not (targetSheet Is Nothing) And thisSheet.Name < targetSheet.Name) Then
 
        If (thisSheet.Cells(1, 1) = "Profile Alarms") Then
 
            Call importSheet(thisSheet)
 
        Else
            Call MsgBox("Please select an Alarm sheet")
        End If
    Else
        Call MsgBox("Please select an Alarm sheet")
    End If
 
    Exit Sub
 
failed:
    Call MsgBox("Please select an Alarm sheet")
 
End Sub
 
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
Select Worksheet to print Macro Angel_24477616 Excel Worksheet Functions 0 March 19th 07 12:56 PM
why does this macro select the entire worksheet when run? Dave F Excel Discussion (Misc queries) 6 March 1st 07 01:19 PM
need a macro select all cells in a worksheet? MarkN Excel Discussion (Misc queries) 0 June 23rd 06 12:47 AM
select worksheet to run macro Hidaya Excel Discussion (Misc queries) 5 December 1st 04 11:54 PM
Help Please! Macro Error on Select Worksheet Apressler Excel Programming 1 September 23rd 04 04:58 PM


All times are GMT +1. The time now is 10:02 PM.

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"