ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Matching a date or value (https://www.excelbanter.com/excel-programming/406306-matching-date-value.html)

Eric

Matching a date or value
 
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

WhytheQ

Matching a date or value
 
On 18 Feb, 12:45, Eric wrote:
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


Ker_01

Matching a date or value
 
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

"WhytheQ" wrote in message
...
On 18 Feb, 12:45, Eric wrote:
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




All times are GMT +1. The time now is 07:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com