VBA: Importing 3 csv files into 3 different worksheet


New Member
Nov 30, 2015
Hi all, my currently code imports 1 csv data into sheet 1 and then I have to manually click the button and select the next csv file and import to sheet 2. Im thinking if it is possible to select all 3 csv data and import them to sheet 1, sheet 2 and sheet 3 all at once?

any help is greatly appreciated.

Sub Process()
    Dim strCH As String
    Dim WrtRec As Boolean
    Dim s As String
    Dim v As Variant
    Dim RowNo As Long
    Dim ColNo As Long
    Dim Offset As Integer
    Dim strFilename As String
    strFilename = Application.GetOpenFilename("All Files (*.), *.")
    If strFilename = "" Then Exit Sub
    Dim FileNum As Integer
    FileNum = FreeFile()
    Open strFilename For Input As FileNum
    Dim ws As Worksheet
    Set ws = ActiveWorkbook.ActiveSheet
    Do While Not EOF(FileNum)
        Line Input #1, s
        v = Split(s, vbTab)
        If UBound(v) >= 1 Then
            v(0) = Trim(Replace(v(0), Chr(34), ""))
            Select Case Left(v(0), 3)
                Case "Cha"      'Channel
                    strCH = Trim(Replace(v(1), Chr(34), ""))
                    Select Case strCH
                        Case "CH6"
                            Offset = 1  'Column "A"
                        Case "CH14"
                            Offset = 14 'Column "N"
                        Case Else
                            Offset = 0
                    End Select
                    RowNo = 14
                Case "Nu."
                    WrtRec = True
                Case "---"
                    WrtRec = False
            End Select
            If WrtRec And (Offset > 0) Then
                For ColNo = 0 To UBound(v)
                    ws.Cells(RowNo, ColNo + Offset) = Trim(Replace(v(ColNo), Chr(34), ""))
                Next ColNo
                RowNo = RowNo + 1
            End If
        End If
    Set ws = Nothing
    Close (FileNum)
End Sub


Well-known Member
Oct 4, 2007
I don't think you can pick them all at the same time, but maybe something like this would help.

    strFilename = Application.GetOpenFilename("All Files (*.), *.")
    If strFilename = "" Then Exit Sub

    strFilename2 = Application.GetOpenFilename("All Files (*.), *.")
    If strFilename2 = "" Then Exit Sub

    strFilename3 = Application.GetOpenFilename("All Files (*.), *.")
    If strFilename3 = "" Then Exit Sub


New Member
Nov 30, 2015
Hi Ross, I wished it was that easy but nope. Tried your suggestion. Only the data from the last file was imported and was to sheet 1. Thanks for giving it a go.


Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...