ByVal Target question

Patricia0923

New Member
Joined
Mar 18, 2014
Messages
25
I have created a spreadsheet to do the following...

Upon entering a valid date in cell C1, VBA runs the code for R2D2.

The code I used for this is:

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

Application.Run "R2D2"

This works fine except the spreadsheet will also run if the cell is blank and you click in it and press enter, and it will also run if you put in an invalid date and press enter.

Any suggestions would be appreciated!

Thanks!
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
You could add an IsDate check (it's not perfect as IsDate is pretty lenient, but it will probably do):
Code:
If Target.Address = "$C$1" Then

If IsDate(Range("C1").Value) Then Call R2D2
 
Upvote 0
You could add an IsDate check (it's not perfect as IsDate is pretty lenient, but it will probably do):
Code:
If Target.Address = "$C$1" Then

If IsDate(Range("C1").Value) Then Call R2D2


Thanks for your quick reply.
Yes, that worked perfectly!

You are my hero!!


I just had to add another End If to close the additional If statement.
I have learned so much over the past three weeks!
But there's still sooo much!

Have a great day!
 
Upvote 0

Forum statistics

Threads
1,215,952
Messages
6,127,913
Members
449,411
Latest member
AppellatePerson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top