VBA copy and paste

CassieL

Board Regular
Joined
Jun 14, 2016
Messages
90
Hi everyone, I am new to Macro and I hope you can help me out.

I have 5 tabs "1,2,3,4,5" and I like to copy range B4:Y and paste it to "Total" tab. Each tab has different numbers of row.

How can I do that with Macro.
Please help.

Thanks!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Could you please be more specific about the range of the data you're trying to copy? Is it Columns B to Y, starting row 4, for every tab?
 
Upvote 0
Sorry for the confusion. And yes, Coumn B to Y and starting from row 4 for every tab.

I try to get the code to copy till last row of each tab (cause every tab has different numbers of rows) and paste on "Total"

for example Tab 1 has 50 rows, tab 2 has 34 rows.
The macro will copy the tab 1 50 rows and past on Total tab starting from B4 to B54 and tab 2 data will paste starting from B55.

Thanks for your reply again!
 
Upvote 0
I assumed the name of your sheets are "1", "2" ... You can try something like :

Code:
Sub TransferData()
Dim LTot As Integer ' represents the line in the total tab
Dim WsTot As Worksheet ' represents your sheet tab
Dim i As Integer

Set WsTot=ThisWorkbook.sheets("Total") 'declare your Total tab
WsTot.Range("B4:Y10000").Clear ' clear the old data

For i = 1 To 5 ' numbers of your tabs
    With ThisWorkbook.sheets("" & i)
        .Range(.Cells(4,2),.Cells(.Range("B10000").End(xlUp).Rows,25)).Copy WsTot.Cells(LTot,2)
        LTot=LTot+.Range("B10000").End(xlUp).Rows-4
    End WIth
Next

End Sub
 
Upvote 0
Thank you for your help!! I appreciate that a lot.

What if my tab is name in text instead of numbers?
 
Upvote 0
Well, if their index are 1,2,3,4,5 (meaning they are place in position n°1,2,2,4,5) you can write With ThisWorkbook.Sheets(i).
 
Upvote 0

Forum statistics

Threads
1,223,630
Messages
6,173,454
Members
452,514
Latest member
cjkelly15

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