Dave Peterson said:
Option Explicit
Sub testme()
dim wks as worksheet
dim myCol as long 'a number!!
set wks = thisworkbook.worksheets("My Sheet Name Here")
myCol = 5 'Column E is the 5th column
if lcase(activesheet.name) <> lcase(wks.name) then
exit sub 'not the right sheet
end if
if activecell.column <> mycol then
exit sub
end if
'do your macro here
End if
Untested, uncompiled. Watch for typos!
But you really don't need to do this verification to run against a certain
column. You can run the macro and just operate on that data.
For instance:
Option Explicit
Sub testme2()
dim wks as worksheet
dim myRng as range
dim myCell as range
set wks = thisworkbook.worksheets("My Sheet Name Here")
with wks
set myrng = .range("E1",.cells(.rows.count,"E").end(xlup))
end with
for each mycell in myrng.cells
msgbox mycell.value
next mycell
End if
It won't care what the active workbook is, or what the activesheet is, or
where the activecell is.
(All untested, uncompiled!!)
Many thanks for the helpful replies. This is my (amateur) code, and I only want
to be able to run it when a cell in column G of a worksheet called "Category"
has been selected. I guess if either criteria has not been matched, it would be
perfect is an appropriate message box popped up.
ActiveCell.Select
ActiveCell.FormulaR1C1 = "=R[1]C[-5]"
Selection.Font.Bold = True
Selection.Font.Underline = xlUnderlineStyleSingle
ActiveCell.Resize(1, 6).Select
Selection.Merge
With Selection
.HorizontalAlignment = xlLeft
End With
Thanks,
V