VBA to convert column range of date to long int

Mr80s

New Member
Joined
Sep 1, 2019
Messages
20
Hi Folks,

I have a script that copies ranges (columns) of data from one workbook to another. It copies a column of Dates in format MM/DD/YYYY and I'd like to convert that entire column to long integer.

So here is my code that copies the columns over:

Code:
Dim nmary As Variant, sh1 As Worksheet, sh2 As Worksheet, i As Long, rng As Range, fileLocation As StringDim fileName As String
Set sh1 = ThisWorkbook.ActiveSheet
nmary = Array("Last Name", "First Name", "Student ID", "Role", "End Date", "School Email Address")
Workbooks.Add
Dim col As Range
Dim value(0) As Integer
Set sh2 = ActiveWorkbook.Sheets(1)
    For i = LBound(nmary) To UBound(nmary)
        Set rng = sh1.Rows(inputValue).Find(nmary(i), , xlValues).EntireColumn
        rng.Copy sh2.Cells(1, i + 1)
    Next

I then do some renaming of my column headers:
Code:
sh2.Columns.AutoFit
sh2.Range("A:A").Replace "*Last Name*", "sN", xlWhole
sh2.Range("B:B").Replace "*First Name*", "givenName", xlPart
sh2.Range("C:C").Replace "*Student ID*", "otherIpPhone", xlPart
sh2.Range("D:D").Replace "Role", "templateName", xlPart
sh2.Range("E:E").Replace "*End Date*", "accountExpires", xlPart
sh2.Range("F:F").Replace "*School Email Address*", "mail", xlPart

What I'd like to do is now take all of Column E "End Date" of format MM/DD/YYYY and convert to long integer (needs to be that format to be imported into another program).

I'm trying :
Code:
Dim datevar As Long
For i = 1 To Rows.Count
 datevar = CLng(Cells(i, 5))
 Cells(i, 5) = datevar
Next i

but this A) is way to inefficient and B) doesn't end up converting.

Any ideas?

Thanks!
 
You are welcome! I am glad you got it working now.
 
Upvote 0

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,215,326
Messages
6,124,267
Members
449,149
Latest member
mwdbActuary

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