VBA to export data from multiple csv files based on a value in column B

asad

Well-known Member
Joined
Sep 9, 2008
Messages
1,434
Hi Guys,

I need help in finding a solution to my problem. I need to export data from multiple csv files (all of them in one folder - "Daily Dump Data") based on a value in column B. The value I am looking for is 606. The columns that have data are from A to CP, so basically all columns in the files. The data from all files needs to go into one Excel file and this will be in a new folder - "606 Data".
Is this possible?

Thanks
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I found this code in MrExcel and tried to use it but it gives Type Mismatch #13 error. And it is stopping at row in Red colour below.

VBA Code:
Sub Extract_Data()
    Dim P$, C$, L&, V(), F%, K&, N&, S$(), R&
        P = "H:\Daily Dump Data\"
        C = Dir$(P & "*.csv"):  If C = "" Then Beep: Exit Sub
        While C > "":  L = L + 1:  C = Dir$:  Wend
        ReDim V(1 To L + 1, 1 To L + 1)
        V(L + 1, L + 1) = 0
   With Application
       .StatusBar = "       Processing " & L & " csv files …"
        F = FreeFile
        C = Dir$(P & "*.csv")
    Do
        K = 0
        N = N + 1
        V(N, N) = 0
        Open P & C For Input As #F
        S = Split(Input(LOF(F), #F), vbLf)
        Close #F
   [COLOR=rgb(226, 80, 65)] For R = 2 To .Min(.Match("""#*", S, 0) - 5, 3 + L * 2) Step 2[/COLOR]
        K = K + 1
        V(K + N, N) = Round(Val(Split(Split(S(R), ",")(4), """")(1)), 2)
        V(N, K + N) = V(K + N, N)
    Next
        L = L - 1
        C = Dir$:  If N Mod 300 = 0 Then DoEvents
    Loop Until C = ""
       .SheetsInNewWorkbook = 1
       .StatusBar = False
        Workbooks.Add.Sheets(1).[A1].Resize(N + 1, N + 1).Value2 = V
       .DisplayAlerts = False
        ActiveWorkbook.SaveAs "606 Data ", 51
       .DisplayAlerts = True
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,094
Messages
6,123,071
Members
449,092
Latest member
ipruravindra

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