Modify Column format before saving as csv file

WascoWarrior

New Member
Joined
May 22, 2024
Messages
9
Office Version
  1. 365
Platform
  1. Windows
I have a button in a XLSM spreadsheet that lets the user copy the data to a new sheet and save as a CSV file.
1716386101230.png

What I need to do before saving as a csv file, is modify the format of 2 columns-dates (currently set as text with data represented as mm/dd/yy and change the column so the data is saved as mmddyy (remove the slashes) before saving as a CSV file. How can this be accomplished using VBA. I don't want the user to manually modify the fields.
Sub CmdUploadIFS_Click()
'***************************************************************************************
'*** Save Spreadsheet as csv ***
'***************************************************************************************

Dim MyPath As String
Dim MyFileName As String
Dim FullPath As String
Dim WB1 As Workbook, WB2 As Workbook
Dim rng As Range
Dim todaydate As Date

MyPath = "C:\UPLOAD\UPLOADPO"
Set WB1 = ActiveWorkbook

On Error Resume Next
Set rng = Range("A3:K9999")
If rng Is Nothing Then Exit Sub
On Error GoTo 0
Application.ScreenUpdating = False
rng.Copy

Set WB2 = Application.Workbooks.Add(1)
WB2.Sheets(1).Range("A1").PasteSpecial xlPasteValues
todaydate = Now()
MyFileName = "UPLOADPO_" & Format(todaydate, "yyyymmdd_hhmmss")
FullPath = MyPath & "\" & MyFileName

Application.DisplayAlerts = False
If MsgBox("Data will be copied to: " & MyPath & "\" & MyFileName & vbCrLf & _
"Continue?", vbQuestion + vbYesNo) <> vbYes Then
Exit Sub
End If

If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
With WB2
.SaveAs Filename:=FullPath, FileFormat:=xlCSV, CreateBackup:=True
.Close False
End With
Application.DisplayAlerts = True
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Without being at the computer on which the code is running and using it like the end user, debugging is a back and forth effort. I would have eventually resolved the issue.
 
Upvote 0
Jeffrey, I know you would have solved the issue. Always nice when multiple eyes are looking at the code for solutions.
 
Upvote 0

Forum statistics

Threads
1,223,931
Messages
6,175,465
Members
452,646
Latest member
tudou

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