Combining all worksheets but one in same workbook

rachel06

Board Regular
Joined
Feb 3, 2016
Messages
84
Office Version
  1. 365
Platform
  1. Windows
Hello,

This one should be pretty easy. I want to combine all of the sheets in my workbook into one minus the "Dashboard" sheet. I found this code that works for the most part, I just haven't been able to get the code to ignore the "Dashboard" sheet.


Sub CombineAP35()

Dim i As Integer
Dim xTCount As Variant
Dim xWs As Worksheet
On Error Resume Next
LInput:
xTCount = Application.InputBox("The number of title rows", "", "1")
If TypeName(xTCount) = "Boolean" Then Exit Sub
If Not IsNumeric(xTCount) Then
MsgBox "Only can enter number"
GoTo LInput
End If
Set xWs = ActiveWorkbook.Worksheets.Add(Sheets(1))
xWs.Name = "Combined"
Worksheets(2).Range("A1").EntireRow.Copy Destination:=xWs.Range("A1")
For i = 2 To Worksheets.Count
Worksheets(i).Range("A1").CurrentRegion.Offset(CInt(xTCount), 0).Copy _
Destination:=xWs.Cells(xWs.UsedRange.Cells(xWs.UsedRange.Count).Row + 1, 1)
Next
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi Rachel,

Try this:

VBA Code:
Option Explicit
Sub CombineAP35()

    Dim i As Integer
    Dim xTCount As Variant
    Dim xWs As Worksheet

    On Error Resume Next
    
LInput:
    xTCount = Application.InputBox("The number of title rows", "", "1")
    If TypeName(xTCount) = "Boolean" Then Exit Sub
    If Not IsNumeric(xTCount) Then
        MsgBox "Only can enter number"
        GoTo LInput
    End If

    Set xWs = ActiveWorkbook.Worksheets.Add(Sheets(1))
    xWs.Name = "Combined"
    Worksheets(2).Range("A1").EntireRow.Copy Destination:=xWs.Range("A1")
    For i = 2 To Worksheets.Count
        If StrConv(Worksheets(i).Name, vbProperCase) <> "Dashboard" Then
            Worksheets(i).Range("A1").CurrentRegion.Offset(CInt(xTCount), 0).Copy _
            Destination:=xWs.Cells(xWs.UsedRange.Cells(xWs.UsedRange.Count).Row + 1, 1)
        End If
    Next i
    
End Sub

Note the way it currently stands the code will only consolidate the data if there's no sheet called "Combined" in the workbook to start with.

Regards,

Robert
 
Upvote 0
Solution
another option is Power Query

I always forget about Power Query! I use that with Power BI on my personal computer, but I don't know that I have access to that at work. I like to make things really simple for my colleagues at work - clicking a button and having it do its thing. I appreciate the reminder about PowerQuery though! I have to start using that more.
 
Upvote 0
Rachel,
If you are running 365 at work then it is called Get and Transform. It is native in 2016 and 2019 also. Needs to be added in if using 2010 or 2013.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,858
Members
449,052
Latest member
Fuddy_Duddy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top