Link to home
Start Free TrialLog in
Avatar of WeThotUWasAToad
WeThotUWasAToad

asked on

Modification questions re VBA code to merge multiple worksheets to a single summary worksheet in Excel

Hello,

This is a follow-up to an earlier question posted here:

Combine multiple sorted Excel worksheets to a single summary worksheet which is also sorted

The main question in that thread was:
Is there an Excel formula (or formulas) which will merge data from multiple worksheets into a single summary worksheet and keep the combined rows sorted?

Please refer to the earlier thread for detailed examples and screenshots.

The questions below refer to the solution in the previous thread which is also included here for convenience:

Sub CombineSheets()
    ' loop all sheets and combine
    For Each ws In Sheets
        ws.Select
        ' if 1st sheet, clear first
        If (ws.Name = "Combined") Then
            Range("B4:G4").Select
            Range(Selection, Selection.End(xlDown)).Select
            Selection.ClearContents
        Else
            ' for other sheets, copy and paste into first one
            Range("B4:G4").Select
            Range(Selection, Selection.End(xlDown)).Select
            Selection.Copy
            Sheets("Combined").Select
            
            Range("B4").Select
            If ActiveCell.Text <> "" Then
                Selection.End(xlDown).Select
                ActiveCell.Offset(1).Select
            End If
            
            ActiveSheet.Paste
        End If
    Next
    
    ' now sort them
    Sheets("Combined").Select
    
    Dim LastRow As Long
    LastRow = Cells(Rows.Count, 2).End(xlUp).Row
    
    Range("B4:G4").Select
    Range(Selection, Selection.End(xlDown)).Select
    
    ActiveWorkbook.Worksheets("Combined").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Combined").Sort.SortFields.Add Key:=Range("C4:C" & LastRow), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Combined").Sort
        .SetRange Range("B4:G" & LastRow)
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub

Open in new window


Questions

1) Where & how should the code be changed to include a different range of cells — both in the account worksheets and in the summary worksheet?
2) Will the current code still function correctly if a large number of transactions are added to any of the account worksheets?
3) Can additional columns (and/or rows) be inserted into the current range (understanding that all worksheets must have identical ranges) without affecting the results?
4) Does the code require any changes if a graphic (placed in the summary sheet) is to be used as an activation button?
5) If additional accounts (ie additional worksheets) are added to the workbook, will the code automatically include them in the summary?
6) If not, how can the above be facilitated?
7) Can additional non-account worksheets be added to the workbook without affecting the summary outcome?
8) Can the code be modified so that it runs whenever Excel auto-calculates rather than requiring an additional step to run the macro as is the case now? For an example of VBA code which includes this feature (ie running with auto-calculation and therefore not requiring an additional keystroke), please refer to this solution (by Rory Archibald) to another thread:
https://www.experts-exchange.com/questions/28247088/Code-to-create-filtering-box-at-the-top-of-several-columns-in-Excel.html?anchorAnswerId=39523832#a39523832

Thanks
ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WeThotUWasAToad
WeThotUWasAToad

ASKER

Another question:

9) Can the code be modified so that the process of placing the data into the summary (ie "Combined" worksheet) occur as a Paste Value rather than a typical Paste? The reason is that portions of the source worksheets will contain formulas rather than simple entries.

For example, I will be using the following formula* in column B to make sure there is no error in the account number for a given transaction:

=MID(CELL("filename",B4),FIND("]",CELL("filename",B4))+1,255)

So when that formula is in use in an account worksheet, column B displays the correct 4-digit account number. But after the macro runs, that same formula is pasted into column B of the summary sheet and consequently displays "Combined".

*From https://www.extendoffice.com/documents/excel/2618-excel-reference-tab-name.html
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial