Consulting

Page 2 of 2 FirstFirst 1 2
Results 21 to 24 of 24

Thread: Loop Through Multiple Workbooks/Sheets And Extract Values From Columns With Label

  1. #21
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Here is my test sample
    Attached Files Attached Files
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  2. #22
    VBAX Regular
    Joined
    Jan 2016
    Posts
    55
    Location
    It worked after I changed this line of code:

    Filename = Dir(Path & "*.xls*")
    to:

    Filename = Dir(Path & "*.xlsx")
    My AllItems file previously had extension as xlsx instead of xlsm. Maybe that was the reason why it kept opening file that is already open.

    mdmackillop and MINCUS1308, thank you so much for helping me with this macro. I am learning from the best.

  3. #23
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Happy you got it sorted.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #24
    VBAX Newbie
    Joined
    Jun 2018
    Posts
    2
    Location
    Hello All, i would like to copy the paste these values in the masterfile but keeping the original format ?
    i have several workbooks ans i want to copy the values from the four columns A22 TO LastRow to my masterfile
    pasting the below each other
    is this possible ???

    i suppose that the INTERSECT Is the problem here but i dont know with what i can replace this part of the code ?

    Quote Originally Posted by mdmackillop View Post
    Yes. or change this to suit
    Path = ThisBk.Path & "\"
    Minor revisions
    Option Explicit
    Option Compare Text
    Sub test()
        Dim Rng
        Dim sht As Worksheet
        Dim wbk As Workbook
        Dim Filename As String
        Dim Path As String
        Dim ThisBk As Workbook
        Dim Tgt As Range
        Dim Arr, a
        Dim c As Range
        Application.ScreenUpdating = False
        Application.EnableEvents = False
        Arr = Array("ItemID", "XItemID")
        Set ThisBk = ActiveWorkbook
        Path = ThisBk.Path & "\"
        Filename = Dir(Path & "*.xls*")
        Do While Len(Filename) > 0
            If Filename <> ThisWorkbook.Name Then
                Set wbk = Workbooks.Open(Path & Filename, UpdateLinks:=False)
                For Each sht In wbk.Worksheets
                    For Each a In Arr
                        Set c = sht.Rows(1).Find(a)
                        If Not c Is Nothing Then
                            Set Tgt = ThisBk.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp)(2)
                            On Error Resume Next
                            Intersect(c.EntireColumn, sht.UsedRange).Copy Tgt
                            On Error GoTo 0
                        End If
                    Next a
                Next sht
                wbk.Close True
            End If
            Filename = Dir
        Loop
        On Error Resume Next    ThisBk.Sheets("Sheet1").Columns(1).SpecialCells(xlCellTypeBlanks).Delete
        ThisBk.Sheets("Sheet1").Columns(1).SpecialCells(xlCellTypeConstants, xlErrors).Delete
        On Error GoTo 0
        Application.EnableEvents = True
        Application.ScreenUpdating = True
    End Sub
    Last edited by EMRBR; 06-07-2018 at 02:19 PM.

Posting Permissions

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