Multiply all DATE cells (some are text formatted) by 1 using VBA.

Anne Troy

MrExcel MVP
Joined
Feb 18, 2002
Messages
2,632
Office Version
  1. 365
Platform
  1. Windows
SORRY--I CHANGED THE METHOD I'M FOCUSING ON, BUT I DON'T CARE HOW IT'S DONE. Only need to do this once on 6 files with about 20 worksheets each.

I have 6 files with thousands of records in each. Someone must've changed their SQL query because the first half of the month shows as actual date values and the rest of the month is text dates.

The code below works, but I have to select the range.
I want it to work on column D from 2nd row to last row.
I want it to work on ALL worksheets in the workbook.

VBA Code:
Sub ConvertStringToDate()

    Dim i As Integer

    For i = 2 To 5000
   
        Range("D" & i) = CDate(Range("D" & i))
    Next i
   
End Sub

Halp!! AND THANKS IN ADVANCE!
 
Last edited:
OK, I think I see what is going on. It looks like they are all coming over as dates, but not maybe not in the format that you want.
It looks like it confused some of the tabs and April 3 is coming over as March 4 (3/4/2023 is being interpretted as March 4 instead of April 3).
I have seen this when exporting from a system that uses a European date format and importing to a system that uses an American Date format.
And if it is using an American format of m/d/yyyy, and try to import a date like 13/4/2023, it will automatically make it text, since there is no month 13.

So I think you may either need to change how the data is being exported out of SQL, or change how it is coming into Excel, so there is consistency there (i.e. both using American formats, or both using European formats).
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Yep. It's a one-time deal. Not gonna happen. Because you can't POSSIBLY ask the customer to re-run the data. /s

Joe, thanks so much! Yoodaman.
 
Upvote 0
If the dates are appearing in DMY format with the original data change the array in the Text to Columns code to
Rich (BB code):
=Array(1, 4)
Then format the column how you wish
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,089
Messages
6,123,058
Members
449,091
Latest member
ikke

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