having a macro work only on a worksheet

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
 
F

Frank Kabel

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?
 
D

Don Guillett

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?
 
B

Bob Phillips

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top