Consolidate CSV Files

marka87uk

Board Regular
Joined
Mar 24, 2007
Messages
247
Hi,

I have a folder containing about 100 CSV files. (P:\Uploads\)

1. I'd like a method of consolidating all CSV files into one master CSV file so that it can be uploaded into a program which can only accept one CSV file at a time.

2. The files contain some blank entries which appear at the end of each file e.g.
,,,,,
,,,,,
,,,,,

I'd like to remove these blank entries in the master file so that they do not slow down the upload process.

Any help would be much appreciated! :)
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
This DOS command can be used as the basis, so you save a lot of VBA code.

Code:
copy P:\Uploads\file*.csv P:\Uploads\bigfile.csv

Here, I assume the smaller files start with the word file. The consolidated one is called bigfile.csv

This will get you started for the code.
 
Upvote 0
To add onto Wigi's suggestion,
here is a vba code for using command prompts.

Code:
Public Sub TestCommandLine()
    Const lngCancelled_c As Long = 0
    Dim strCmd As String
    strCmd = VBA.InputBox("Enter DOS Command:", "Enter Command", "dir")
    If VBA.LenB(strCmd) = lngCancelled_c Then
        Exit Sub
    End If
    CommandLine strCmd, True
    'CommandLine "ipconfig /all", True
End Sub
Public Function CommandLine(command As String, Optional ByVal keepAlive As _
    Boolean = False, Optional windowState As VbAppWinStyle = VbAppWinStyle.vbHide) _
    As Boolean
     '--------------------------------------------------------------------------------
     ' Procedure : CommandLine
     ' Author    : Aaron Bush (Oorang)
     ' Date      : 10/02/2007
     ' Purpose   : Provides a simple interface to execute a command lines from VBA.
     ' Input(s)  :
     '               command     : The DOS command you wish to execute.
     '               keepAlive   : Keeps the DOS window open *after* command has been
     '                             executed. Default behavior is to auto-close. (See
     '                             remarks section for additional information.)
     '               windowState : Determines the window state of the DOS prompt
     '                             *during* command execution.
     ' Output    : True if completed with no errors, False if error encountered.
     ' Remarks   : If the windowState property is set to vbHide while the keepAlive
     '             parameter is set to True, then windowState will be changed to
     '             vbNormalFocus.
     '--------------------------------------------------------------------------------
    On Error GoTo Err_Hnd
    Const lngMatch_c As Long = 0
    Const strCMD_c As String = "cmd.exe"
    Const strComSpec_c As String = "COMSPEC"
    Const strTerminate_c As String = " /c "
    Const strKeepAlive_c As String = " /k "
    Dim strCmdPath As String
    Dim strCmdSwtch As String
    If keepAlive Then
        If windowState = vbHide Then
            windowState = vbNormalFocus
        End If
        strCmdSwtch = strKeepAlive_c
    Else
        strCmdSwtch = strTerminate_c
    End If
    strCmdPath = VBA.Environ$(strComSpec_c)
    If VBA.StrComp(VBA.Right$(strCmdPath, 7), strCMD_c, vbTextCompare) <> _
    lngMatch_c Then
        strCmdSwtch = vbNullString
    End If
    VBA.Shell strCmdPath & strCmdSwtch & command, windowState
    CommandLine = True
    Exit Function
Err_Hnd:
    CommandLine = False
End Function
 
Upvote 0

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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