View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Frank Kabel Frank Kabel is offline
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