+ Reply to Thread
Results 1 to 3 of 3

Copying data from specific cells in multiple Workbooks in a folder and Consolidating it

Hybrid View

Tristanfrontline Copying data from specific... 05-05-2014, 08:43 PM
millz Re: Copying data from... 05-05-2014, 10:14 PM
Tristanfrontline Re: Copying data from... 05-05-2014, 11:27 PM
  1. #1
    Registered User
    Join Date
    09-16-2013
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    38

    Copying data from specific cells in multiple Workbooks in a folder and Consolidating it

    Hi Guys
    I have a macro which I have found and it works really well except I have 2 issues

    1 - The code only copies formulas and not just plain values
    2 - I cant work out how to make it copy from specific cells

    Where it says
    lngrow = lngrow + 1
    ws.Rows(2).Copy ws1.Cells(lngrow, "A")

    I want to change that to copy the values from c65 & c67. I have tried altering the lines to try and copy a range but whatever I do it doesnt work. I am new to VBA and have also been trying to find definitions of VBA commands and codes but those commands do not seem to be in anything I have read. I understand lng is there because VBA recognises row as a command but other than that my knowledge is very limited. Any help on this would be greatly appreciated thank you

    The code I am using is:
    Sub ConFiles()
    
        Dim Wbname As String
        Dim Wb As Workbook
        Dim ws As Worksheet
        Dim ws1 As Worksheet
        Dim lngCalc As Long
        Dim lngrow As Long
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            lngCalc = .CalculationState
            .Calculation = xlCalculationManual
        End With
    
    
       Set ws1 = ThisWorkbook.Sheets.Add
        'change folder path here
        FolderName = "C:\Users\James\Dropbox\Excel\Testing\VBA Testing\"
        Wbname = Dir(FolderName & "\" & "*.xls*")
    
        'ThisWorkbook.Sheets(1).UsedRange.ClearContents
        Do While Len(Wbname) > 0
            Set Wb = Workbooks.Open(FolderName & "\" & Wbname)
            Set ws = Nothing
            On Error Resume Next
            'change sheet name here
            Set ws = Wb.Sheets("Total Quantities")
            On Error GoTo 0
            If Not ws Is Nothing Then
            lngrow = lngrow + 1
            ws.Rows(2).Copy ws1.Cells(lngrow, "A")
            End If
            Wb.Close False
            Wbname = Dir
        Loop
    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
            .Calculation = lngCalc
        End With
    End Sub

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Copying data from specific cells in multiple Workbooks in a folder and Consolidating i

    Try the amendment:
    Sub ConFiles()
    
        Dim Wbname As String
        Dim Wb As Workbook
        Dim ws As Worksheet
        Dim ws1 As Worksheet
        Dim lngCalc As Long
        Dim lngrow As Long
    
        With Application
            .ScreenUpdating = False
            .EnableEvents = False
            lngCalc = .CalculationState
            .Calculation = xlCalculationManual
        End With
    
    
       Set ws1 = ThisWorkbook.Sheets.Add
        'change folder path here
        FolderName = "C:\Users\James\Dropbox\Excel\Testing\VBA Testing\"
        Wbname = Dir(FolderName & "\" & "*.xls*")
    
        'ThisWorkbook.Sheets(1).UsedRange.ClearContents
        Do While Len(Wbname) > 0
            Set Wb = Workbooks.Open(FolderName & "\" & Wbname)
            Set ws = Nothing
            On Error Resume Next
            'change sheet name here
            Set ws = Wb.Sheets("Total Quantities")
            On Error GoTo 0
            If Not ws Is Nothing Then
            lngrow = lngrow + 1
            ws.Range("C65").Copy
            ws1.Cells(lngrow, "A").PasteSpecial xlPasteValues
            ws.Range("C67").Copy
            ws1.Cells(lngrow, "B").PasteSpecial xlPasteValues
            End If
            Wb.Close False
            Wbname = Dir
        Loop
    
        With Application
            .ScreenUpdating = True
            .EnableEvents = True
            .Calculation = lngCalc
        End With
    End Sub
    I assume you want to paste them side by side (columns A and B)
    多么想要告诉你 我好喜欢你

  3. #3
    Registered User
    Join Date
    09-16-2013
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Copying data from specific cells in multiple Workbooks in a folder and Consolidating i

    Thanks heaps for that it worked a treat

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copying specific data ranges from multiple (closed or in use by others) workbooks
    By TheRetroChief in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-19-2014, 10:39 AM
  2. Consolidating a specific worksheet from multiple workbooks into one master
    By kikar in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2013, 11:22 AM
  3. Conditioned copying/pasting of specific cells from multiple workbooks to master workbook
    By Ziad Homaidan in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-06-2013, 11:39 AM
  4. Macro to extract data from multiple workbooks, specific sheet, specific cells
    By crissandraauree in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2012, 03:54 PM
  5. Consolidating from multiple workbooks - copying final data, not formulas
    By BradPhillips in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2012, 02:25 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1