picklefactory
Well-known Member
- Joined
- Jan 28, 2005
- Messages
- 508
- Office Version
- 365
- Platform
- Windows
Hi folks, I'm back again.
Working through a new addition to an existing WB. I am creating and saving a range of values as .csv file, which is the required format to upload to a suppliers portal. No problem so far, but what has me stumped is just formatting the cells in the .csv to simply align all columns left and autofit the column widths to suit the values, I'm only using 3 columns A:C. I have tried numerous things, all of which have failed spectacularly..... well not so spectacular, just a whole lot of absolutely nothing happening at all with regard to the formatting.
This was my latest failure, I've tried various options, I get no errors, it creates and saves the .csv fine, it just ignores the formatting completely.
Can anyone point where I'm going wrong, please?
Working through a new addition to an existing WB. I am creating and saving a range of values as .csv file, which is the required format to upload to a suppliers portal. No problem so far, but what has me stumped is just formatting the cells in the .csv to simply align all columns left and autofit the column widths to suit the values, I'm only using 3 columns A:C. I have tried numerous things, all of which have failed spectacularly..... well not so spectacular, just a whole lot of absolutely nothing happening at all with regard to the formatting.
This was my latest failure, I've tried various options, I get no errors, it creates and saves the .csv fine, it just ignores the formatting completely.
Can anyone point where I'm going wrong, please?
VBA Code:
Sub Export_to_CSV()
Dim MyPath As String
Dim MyFileName As String
MyPath = "M:\COMPANY SHARED\wages 2\CSV Exports\"
MyFileName = Worksheets("NEW PAYROLL").Range("K1").Text
Application.ScreenUpdating = False
Sheets("NEW PAYROLL").Select
Range("L1:N40").Select
Selection.Copy
With Workbooks.Add(xlWBATWorksheet)
.Sheets(1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Application.DisplayAlerts = False
.SaveAs Filename:=MyPath & MyFileName, FileFormat:=xlCSV, CreateBackup:=False
Application.DisplayAlerts = True
Range("A1:C50").EntireColumn.AutoFit
ActiveSheet.Cells.HorizontalAlignment = xlLeft
.Close False
End With
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Last edited: