If and Then statement to run VBA

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
797
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hello - I am trying to create a if/then statement so if two dates equal it does this in code, if two dates don't equal it does this. but i am getting a mismatch error even before i get to my If and then statement:

Here is my code what am i doing wrong?

The ranges have formulas in them if that even matters

TODAY is just =TODAY()
FFWD just pulls last day prior to a BD or Holiday.

VBA Code:
Sub RUN()
    Dim FFWD&
    Dim Today$

'Set Range
FFWD = Workbooks("XXXX").Sheets("COMPARE").Range("FFWD")
Today = Workbooks("XXXX").Sheets("COMPARE").Range("Today")

'check if today isn't weekend or holiday and run macro
If FFWD = Today Then
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Are both names ranges single cells?

If so, then I am guessing that the values you are pulling from are NOT both dates (perhaps one is a "date entered as text").

I would declare both variables as dates in your code too, to help avoid this situation, i.e.
VBA Code:
Dim FFWD as Date
Dim Today as Date
Then, if you get an error trying to set the value of each one, then you now the entry is not a date.
 
Upvote 0
Solution
Are both names ranges single cells?

If so, then I am guessing that the values you are pulling from are NOT both dates (perhaps one is a "date entered as text").

I would declare both variables as dates in your code too, to help avoid this situation, i.e.
VBA Code:
Dim FFWD as Date
Dim Today as Date
Then, if you get an error trying to set the value of each one, then you now the entry is not a date.
That seem to have worked!
 
Upvote 0

Forum statistics

Threads
1,216,096
Messages
6,128,809
Members
449,468
Latest member
AGreen17

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