+ Reply to Thread
Results 1 to 1 of 1

vba consolidate

  1. #1
    Registered User
    Join Date
    01-18-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    39

    Question vba consolidate

    is there a way to use select.consolidate with application.workbooks.open

    I want to consolidate multiple workbooks but ever week it's going to be a different set of wokbooks ( different file names).

    so with a macro button the person with the master work book will be able to press on the button choose the files and the consolidate
    thx in advence.



    Ok for now this is what i have it works but i want to simplify :
    Sub MergeSelectedWorkbooks()
    Dim SummarySheet As Worksheet
    Dim FolderPath As String
    Dim SelectedFiles() As Variant
    Dim NRow As Long
    Dim FileName As String
    Dim NFile As Long
    Dim WorkBk As Workbook
    Dim SourceRange As Range
    Dim i As Long
    Dim DestRange As Range

    ' Create a new workbook and set a variable to the first sheet.
    'Set SummarySheet = Workbooks.Add(xlWBATWorksheet).Worksheets(1)

    ' Modify this folder path to point to the files you want to use.
    FolderPath = "C:\Users\home\Desktop\test amt\"

    ' Set the current directory to the the folder path.
    ChDrive FolderPath
    ChDir FolderPath

    ' Open the file dialog box and filter on Excel files, allowing multiple files
    ' to be selected.
    SelectedFiles = Application.GetOpenFilename( _
    filefilter:="Excel Files (*.xl*), *.xl*", MultiSelect:=True)

    ' NRow keeps track of where to insert new rows in the destination workbook.
    NRow = 1

    ' Loop through the list of returned file names
    For NFile = LBound(SelectedFiles) To UBound(SelectedFiles)
    ' Set FileName to be the current workbook file name to open.
    FileName = SelectedFiles(NFile)

    ' Open the current workbook.
    Set WorkBk = Workbooks.Open(FileName)

    ' Set the cell in column A to be the file name.
    'SummarySheet.Range("A" & NRow).Value = FileName

    ' Set the source range to be A9 through C9.
    ' Modify this range for your workbooks. It can span multiple rows.
    Set SourceRange = WorkBk.Worksheets(2).Range("A6:H32")






    ' Set the destination range to start at column B and be the same size as the source range.
    Set DestRange = Sheet2.Range("B" & NRow)
    Set DestRange = DestRange.Resize(SourceRange.Rows.Count, _
    SourceRange.Columns.Count)

    ' Copy over the values from the source to the destination.
    DestRange.Value = SourceRange.Value

    ' Increase NRow so that we know where to copy data next.
    NRow = NRow + DestRange.Rows.Count

    ' Close the source workbook without saving changes.
    WorkBk.Close savechanges:=False
    Next NFile

    ' Call AutoFit on the destination sheet so that all data is readable.
    'SummarySheet.Columns.AutoFit

    '==================================================================================================

    Dim xlastrow As Integer
    Dim xrow As Integer
    xrow = 1

    Range("b65000").End(xlUp).Select
    xlastrow = ActiveCell.Row

    Do Until xrow = xlastrow

    If Cells(xrow, 2).Value = "" Then
    Cells(xrow, 1).Select
    Selection.EntireRow.delete

    xrow = xrow - 1
    xlastrow = xlastrow - 1
    End If

    xrow = xrow + 1

    Loop




    End Sub

    and in the cell i'm using if sum formula to add up all duplicates.

    can someone approve !!
    Last edited by K-Ching; 03-01-2015 at 09:20 AM.

+ 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. [SOLVED] Consolidate with vba
    By Aris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-06-2014, 08:10 AM
  2. Consolidate?
    By mrggutz in forum Excel General
    Replies: 0
    Last Post: 03-22-2010, 10:19 PM
  3. Consolidate
    By Jimmy0306 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-10-2010, 05:41 PM
  4. Consolidate
    By shadad in forum Excel General
    Replies: 4
    Last Post: 01-12-2010, 01:36 PM
  5. [SOLVED] consolidate
    By Consolidt in forum Excel General
    Replies: 1
    Last Post: 05-17-2006, 01:50 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