having a macro work only on a worksheet

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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 said:
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?
 
Sub colorit()
With Sheets("sheet1").Range("A1:B1").Interior
.ColorIndex = 4
.Pattern = xlSolid
End With
End Sub
--
Don Guillett
SalesAid Software
(e-mail address removed)
dennc01 said:
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?
 
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 said:
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?
 
Back
Top