Matching a date or value

E

Eric

Hello everyone,

I need a macro that checks to see if a date matches from another
spreadsheet. If it does I need the macro to continue running if it doesn't
match I need a message box to pop up and ask "is this okay", yes or no.

if yes macro continues (I already have the macro written to continue)

if no macro stops

ie:
JMF Targets=Range "B9" ~~~> This is where the date will be input

JMF Changes= Range "B500" ~~> this is where the date needs to match

Any help would be appreciated. Thank you very much and I hope yo have a
great day.

Eric
 
W

WhytheQ

Hello everyone,

I need a macro that checks to see if a date matches from another
spreadsheet.  If it does I need the macro to continue running if it doesn't
match I need a message box to pop up and ask "is this okay", yes or no.

if yes macro continues (I already have the macro written to continue)

if no macro stops

ie:
JMF Targets=Range "B9"  ~~~> This is where the date will be input

JMF Changes= Range "B500" ~~> this is where the date needs to match

Any help would be appreciated.  Thank you very much and I hope yo have a
great day.

Eric


maybe something like:

if Range("B9") = Range("B500") then
else
if msgbox("Is this ok", vbyesno,"Date difference") = vbno then
End
end if
end if
 
K

Ker_01

WhytheQ's suggestion will work if user interaction is acceptable. Another
option for VBA automation is a simple boolean check to avoid user
interaction on comparisons that pass the test of being the same date. The
thing to be aware of is that Excel may show only the date but still have a
date /and/ time stored. Numerically, dates are integers, and hours/mins/secs
are the decimal part of the cell value. So if you want to do your check in
code, you need to remove the decimal part of each value to make a date-only
comparison. This messagebox also shows the two values in the messagebox so
the user doesn't have to manually find them to compare.

[Aircode, be sure to dim all your variables and (recommended) use option
explicit. Watch for linewrap]

d1 = Sheet1.Range("B9").Value \ 1
d2 = Sheet1.Range("B500").Value \ 1

'to make what shows up in your msgbox readable as a date
FinalDate1 = CDate(d1)
FinalDate2 = CDate(d2)

If d1 <> d2 then
if msgbox ("Is this ok?" & chr(13) & chr(13) & "Date 1: " & FinalDate1
& chr(13) & "Date 2: " & FinalDate2 , vbyesno, "Date Difference") then
end
end if
end if

Hello everyone,

I need a macro that checks to see if a date matches from another
spreadsheet. If it does I need the macro to continue running if it doesn't
match I need a message box to pop up and ask "is this okay", yes or no.

if yes macro continues (I already have the macro written to continue)

if no macro stops

ie:
JMF Targets=Range "B9" ~~~> This is where the date will be input

JMF Changes= Range "B500" ~~> this is where the date needs to match

Any help would be appreciated. Thank you very much and I hope yo have a
great day.

Eric


maybe something like:

if Range("B9") = Range("B500") then
else
if msgbox("Is this ok", vbyesno,"Date difference") = vbno then
End
end if
end if
 

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