Worksheet selectionChange problem

G

Guest

I am trying to run a macro called hardware when the user clicks in cell C14.
I am new to VB in Excel, but use VB in Access.

When I run the following code in debug mode, I can see that it is skipping
the instructions after "then" in the if statement even when the target
address is $C$14. What am I missing?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$c$14" Then
MsgBox "Hardware"
End If
End Sub

Thanks
Sammie
 
G

Guest

Sammie

Try this

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("$c$14"), Target) Is Nothing Then

MsgBox "Hardware"
End If
End Sub


hth
Mark
 
G

Guest

When using this code:

If Target.Address = "$c$14" Then

I got the same result that you did. But using this:

If Target.Address = "$C$14" Then

It worked fine.
 
G

Guest

Thanks. Your code does read the then statement, however, the msgbox doesn't
run the macro. I get a dialog box that says "hardware". Can you help?
 
G

Guest

Wow! As simple as using upper case for the reference! You learn something
every day. Thanks.
Your code does read the then statement, however, the msgbox doesn't run the
macro. I get a dialog box that says "hardware". Can you help?
Sammie
 
D

Dave Peterson

The msgbox isn't ever going to run a macro.

Maybe you want to call the macro after the msgbox:

MsgBox "Hardware"
Call whateverprocedureyouaretryingtorun

?????
 
G

Guest

Dave Peterson said:
The msgbox isn't ever going to run a macro.

Maybe you want to call the macro after the msgbox:

MsgBox "Hardware"
Call whateverprocedureyouaretryingtorun

?????
Sammie
 

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