Column Formatting issue - VBA importing multiple CSV files into one Excel sheet.

heathball

Board Regular
Joined
Apr 6, 2017
Messages
135
Office Version
  1. 365
Platform
  1. Windows
This code works well and fits the purpose, but there is a problem column - "P" - the formatting of the text is, by example
76: 11-9-13

(maximum 3 digits in all 4 sections, always numbers, with a space after the colon)

I am looking for any pathway that does not end like this....

45050.46111 or 01-01-23 10.01

I'm thinking the solution must begin with an accurate custom format...

Unless there is a way to use both delimiters ( : - ) and separate the data into four number formatted columns, which could be placed to the right of the far right column (it is a fixed csv file, always containing 18 columns, ending at column R.)

A solution which ends in the correct text - through creative formatting - would also be a great result. (i have been toiling away at this for a while.)

Any help would be greatly appreciated.





Excel Formula:
Sub CombineCsvs()


Dim FolderPath As String
Dim FileName As String
Dim wbResult As Workbook
Dim WB As Workbook


  FolderPath = "D:\Aible\bin\Merge"
  If FolderPath Like "*[!\/]" Then
    FolderPath = FolderPath & "/"
  End If
 
  FileName = Dir(FolderPath & "*.csv")
 
  Set wbResult = Workbooks.Add
 
  Application.DisplayAlerts = False
  Application.ScreenUpdating = False
 
  Do While FileName <> vbNullString
    Set WB = Workbooks.Open(FolderPath & FileName)
    WB.ActiveSheet.UsedRange.Copy wbResult.ActiveSheet.UsedRange.Rows(wbResult.ActiveSheet.UsedRange.Rows.Count).Offset(1).Resize(1)
    WB.Close False
    FileName = Dir()
  Loop
 
  wbResult.ActiveSheet.Rows(1).EntireRow.Delete
 
  Application.ScreenUpdating = True
  Application.DisplayAlerts = True

 
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Please update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using, as the best solution often varies by version. Don’t forget to scroll down to save your changes.

Please provide some sample data and expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data, allowing us to copy/paste it to our Excel spreadsheets to work with the same data you are. As of October 2023, the latest version is 2.1. Instructions on using this tool can be found here: XL2BB Add-in

Note that this board also has a "Test Here” forum. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Thanks,

Doug
 
Upvote 0
Solution
Please update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using, as the best solution often varies by version. Don’t forget to scroll down to save your changes.

Please provide some sample data and expected results.

MrExcel has a tool called “XL2BB” that lets you post samples of your data, allowing us to copy/paste it to our Excel spreadsheets to work with the same data you are. As of October 2023, the latest version is 2.1. Instructions on using this tool can be found here: XL2BB Add-in

Note that this board also has a "Test Here” forum. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

Thanks,

Doug
Thanks Doug,

Perhaps i am not clear about how my post is being read. I think my post is not clear.


I have updated my account details.

I have also installed XL2BB.

I will work on some extended examples of this code, with further attempts at solving it, and perhaps try a new post in the near future.

Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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