Loop each sheet then paste data insert cell down to Master sheet

SamKhem

Board Regular
Joined
Mar 18, 2024
Messages
50
Office Version
  1. 2016
Platform
  1. Windows
Dear Senior member

I would like request you to guide vba code as example: loop sheet1 to sheet3 then paste data insert cell down to sheet "Master" as information below
Sheet1Sheet2Sheet3Master
No.Menu 1Menu 2No.Menu 1Menu 2No.Menu 1Menu 2No.Menu 1Menu 2
1abcabc1hellohello1GoodGood1abcabc
2abcabc2hellohello2GoodGood2abcabc
3abcabc3hellohello3GoodGood3abcabc
4abcabc4hellohello4GoodGood4abcabc
5abcabc5hellohello5abcabc
6abcabc6hellohello6abcabc
7abcabc7abcabc
8abcabc8abcabc
9abcabc9abcabc
10abcabc10abcabc
11abcabc11abcabc
12abcabc12abcabc
13abcabc13abcabc
14hellohello
15hellohello
16hellohello
17hellohello
18hellohello
19hellohello
20GoodGood
21GoodGood
22GoodGood
23GoodGood
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
What ranges will this data appear in?
Will the lists always be in columns A and B, and start at the very top (row 1)?
 
Upvote 0
If all my assumptions are above are correct, this code should do what you want.
VBA Code:
Sub CombineData()

    Dim ws As Worksheet
    Dim lr As Long
    
    Application.ScreenUpdating = False
    
'   Loop through all worksheets
    For Each ws In ActiveWorkbook.Worksheets
'       Check to see if it is not Master sheet
        If ws.Name <> "Master" Then
'           Copy data to bottom of Master sheet
            ws.Range("A1").CurrentRegion.Offset(1, 0).Copy Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        End If
    Next ws
    
'   Find last row in column A with data on Master sheet
    lr = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row
'   Populate counter formula in column A of Master sheet
    Sheets("Master").Range("A2:A" & lr).FormulaR1C1 = "=ROW()-1"
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 1
Solution
If all my assumptions are above are correct, this code should do what you want.
VBA Code:
Sub CombineData()

    Dim ws As Worksheet
    Dim lr As Long
   
    Application.ScreenUpdating = False
   
'   Loop through all worksheets
    For Each ws In ActiveWorkbook.Worksheets
'       Check to see if it is not Master sheet
        If ws.Name <> "Master" Then
'           Copy data to bottom of Master sheet
            ws.Range("A1").CurrentRegion.Offset(1, 0).Copy Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
        End If
    Next ws
   
'   Find last row in column A with data on Master sheet
    lr = Sheets("Master").Cells(Rows.Count, "A").End(xlUp).Row
'   Populate counter formula in column A of Master sheet
    Sheets("Master").Range("A2:A" & lr).FormulaR1C1 = "=ROW()-1"
   
    Application.ScreenUpdating = True
   
End Sub
Worked perfect. Thank for support.
Have a nice weekend!
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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