Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default having a macro work only on a worksheet

I have a simple sub to highlight some cells, is there anyway to make this run on only sheet 1 but not sheet 2 and 3 in a workbook when I press Ctrl+g?

Thanks,

Example

Sub macro1(


' Keyboard Shortcut: Ctrl+

Range("A1:B1").Selec
With Selection.Interio
.ColorIndex =
.Pattern = xlSoli
End Wit
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default having a macro work only on a worksheet

Hi
try
Sub macro1()

'
' Keyboard Shortcut: Ctrl+g
'
if LCase(Activesheet.name) <"sheet1" then
exit sub
end if
with activesheet.Range("A1:B1").interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

"dennc01" schrieb im Newsbeitrag
...
I have a simple sub to highlight some cells, is there anyway to make

this run on only sheet 1 but not sheet 2 and 3 in a workbook when I
press Ctrl+g?

Thanks,

Example:

Sub macro1()

'
' Keyboard Shortcut: Ctrl+g
'
Range("A1:B1").Select
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default having a macro work only on a worksheet

Sub colorit()
With Sheets("sheet1").Range("A1:B1").Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End Sub
--
Don Guillett
SalesAid Software

"dennc01" wrote in message
...
I have a simple sub to highlight some cells, is there anyway to make this

run on only sheet 1 but not sheet 2 and 3 in a workbook when I press Ctrl+g?

Thanks,

Example:

Sub macro1()

'
' Keyboard Shortcut: Ctrl+g
'
Range("A1:B1").Select
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default having a macro work only on a worksheet

Denn,

Do you mean

Sub macro1()

'
' Keyboard Shortcut: Ctrl+g
'
If Activesheet.Name = "Sheet1" Then
Range("A1:B1").Select
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End If
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"dennc01" wrote in message
...
I have a simple sub to highlight some cells, is there anyway to make this

run on only sheet 1 but not sheet 2 and 3 in a workbook when I press Ctrl+g?

Thanks,

Example:

Sub macro1()

'
' Keyboard Shortcut: Ctrl+g
'
Range("A1:B1").Select
With Selection.Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End Sub



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
Link one worksheet in a workbook to another worksheet in same work bjswise Excel Discussion (Misc queries) 1 February 6th 10 12:09 AM
Macro to update a column in a work based on another work sheet WickerMan New Users to Excel 1 December 4th 09 12:58 PM
Retrieving data into worksheet from another worksheet in same work Tasha Excel Discussion (Misc queries) 2 August 6th 09 03:51 PM
Copying the active worksheet to another worksheet in the same work queenmaam Excel Worksheet Functions 5 March 25th 08 06:56 PM
Macro works Macro does not work Wanna Learn Excel Discussion (Misc queries) 4 March 24th 08 12:51 PM


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

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

About Us

"It's about Microsoft Excel"