Results 1 to 6 of 6

Thread: Copy particular columns from one file to master file with condition

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    Sub test()
        Dim a As Object
        Dim p As String, f As String
        Dim v
        Dim i As Long
        Set a = CreateObject("system.collections.arraylist")
        p = ThisWorkbook.path & "\"
        f = Dir(p & "*.xlsx")
        Do While f <> ""
            With Workbooks.Open(p & f, ReadOnly:=True)
                v =.Sheets(1).Cells(1).CurrentRegion.Value
                For i = 2 To UBound(v)
                    a.Add Array(f, IIf(v(i, 3) = "M", v(i, 3), v(i, 4)), v(i, 5), v(i, 6))
                Next
                .Close
            End With
            f = Dir()
        Loop
        With ThisWorkbook.Sheets(1)
            .UsedRange.Offset(2).ClearContents
            .Cells(3, 1).Resize(a.Count, 4).Value = _
                Application.Transpose(Application.Transpose(a.toarray))
        End With
     End Sub

    マナ
    Last edited by Aussiebear; 07-01-2024 at 03:32 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •