IF a cell is active THEN...

  • Thread starter Thread starter Keith in Portland
  • Start date Start date
K

Keith in Portland

Hi all,

I'm trying to have a conditional statement to reference if a cell is active.
If a cell is active, then run some code, if it is not active, then run some
other code.

Any help is most gracious!

Thanks,
Keith
 
Keith,

If ActiveCell.Address = "$A$1" Then
RunSomeCode
Else
RunSomeOtherCode
End If

You may want to check the sheet name as well - but that depends on your workbook structure

HTH,
Bernie
MS Excel MVP
 
You might try building your code in the Worksheet_SelectionChange event.
When in the VBA window, just double click the sheet where you want the code
to operate. In the code window there are two dropdowns at the top. Select
Worksheet in the left one, and SelectionChange in the right. "Target" is the
range in process of being selected.

example:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Target.Address = "$A$1" Then
[put some code here]
End If

End Sub
 
Whoo-hoo!! It worked and you rock!

And thanks to B Lynn B, too. Thanks y'all!!

Peace,
Keith
 
Back
Top