By: Shamima Sultana

In reply to mill.

Hello Mill,

The VBA code is tailored to operate within a specific workbook context and may not be compatible as a stand-alone Excel Add-in without some adjustments. Add-ins typically work across multiple workbooks, so you need to use the modified code to ensure it can handle different active workbooks, rather than just ThisWorkbook.

To make this VBA code work as an add-in, follow the steps given below:

1. Replace references to ThisWorkbook with ActiveWorkbook.
2. Create a new module within the VBA editor and place your code there. This is necessary for turning it into an add-in.

Sub combine_multiple_sheets_addin()
Dim Row_1, Col_1, Row_last, Column_last As Long
Dim headers As Range
Dim WB As Workbook
Dim wX As Worksheet
Dim Ws As Worksheet

Set WB = ActiveWorkbook ' Change from ThisWorkbook to ActiveWorkbook
Set wX = WB.Sheets.Add
wX.Name = "Consolidated"

' InputBox to select headers
Set headers = Application.InputBox("Choose the Headers", Type:=8)
headers.Copy wX.Range("A1")

Row_1 = headers.Row + 1
Col_1 = headers.Column

' Loop through each worksheet in the active workbook
For Each Ws In WB.Worksheets
If Ws.Name <> "Consolidated" Then
Ws.Activate
Row_last = Cells(Rows.Count, Col_1).End(xlUp).Row
Column_last = Cells(Row_1, Columns.Count).End(xlToLeft).Column
Range(Cells(Row_1, Col_1), Cells(Row_last, Column_last)).Copy _
wX.Range("A" & wX.Cells(Rows.Count, 1).End(xlUp).Row + 1)
End If
Next Ws

Worksheets("Consolidated").Activate
End Sub

3. Once the code is ready, save the workbook as an Excel Add-in (.xlam) file..
4. Install and test the add-in to verify that it works across different workbooks.

Now, this you can use this code as an add-in. If any further issues arise, you can refine the code further depending on their specific needs.

Regards
ExcelDemy