Date formatting issue sheet to VBA Array to Sheet

SimonHow

New Member
Joined
Aug 31, 2023
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I have a number of sheets which I am combining to one sheet using a VBA procedure which collects the data from source sheets, places into a dynamic array (so that can be re dimensioned to deal with different data set sizes) there are a couple of calculations within the array, before passing and appending to a master sheet.

I collect the data using 8 instances of the line of code whether i is telling me which line of data to collect
I pass the data using the second line of code, where the range to pass is defined by the UBound dimension calculated earlier (n) and the next empty row found (NR)
Code:
TArray(3, n) = .Range("E" & i).Value ' Date

NR = .Range("A1048576").End(xlUp).Row + 1
                .Range("A" & NR & ":I" & NR + n).Value = Application.Transpose(TArray)

Everything works perfectly, except an issue that has crept in with date formats, which I only found when the resulting pivot table was sorting incorrectly.

in cell E28 on my source sheet I have the date: 21/03/2022 (in other words 21 March 2022 UK Style)
in cell E29 on my source sheet I have the date: 08/03/2022 (in other words 8 March 2022 UK Style)

the excel format type for column E is date

to the master sheet it passes:

to E28: 21/03/2022 (21 March 2022 - UK Form)
to E29: 03/08/2022 (3 August 2023 UK Form)

any ideas how I can fix this issue

Many thanks advance
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
1709842640129.png
 
Upvote 0
Try wrapping it in CDate or if that doesn't work CLng
VBA Code:
TArray(3, n) = CDate(.Range("E" & i).Value)
or
VBA Code:
TArray(3, n) = CLng(.Range("E" & i).Value)
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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