VBA code to check Date Format

SamarthSalunkhe

Board Regular
Joined
Jun 14, 2021
Messages
103
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I am using below code to check Date format in cell but, I am getting error as Overflow.

Can some one check confirm me where I am updating wrong code.

VBA Code:
Dim UserEnteredDate As Date
Dim CurrentDate As Date

UserEnteredDate = Format(Mid(Sheet3.Cells(5, 7), 2, 2) & Mid(Sheet3.Cells(5, 7), 2, 2) & Right(Sheet3.Cells(5, 7), 4), "DDMMYYYY")
CurrentDate = Format(Now(), "DDMMYYYY")


1663679816467.png
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try changing anything declared as an Integer to a Long. It will not hurt anything and most likely where your issue is.
 
Upvote 0
Note that you are declaring "UserEnteredDate" and "CurrentDate" as dates, but then in your calculations, you are using the FORMAT function.
The FORMAT function returns a Text/String value, not a Date or Number.

Why exactly are you trying to use the FORMAT function on these dates?
What are you ultimately trying to do with these two fields?
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,391
Members
448,957
Latest member
Hat4Life

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