VBA code to copy contents from newly added worksheets to an already existing worksheets on the same workbook

EckanPearl

New Member
Joined
Jul 18, 2015
Messages
3
Hi guys,
I have a macro code that opens up excel files and adds them up to an existing workbook (that is already open) with already 19 worksheets (worksheet names as follows: “result”, “1”, “2”, “3”,.. until “18”).
Now after adding the new worksheets (18 total as well with varying sheet names, and is always changing), I will filter the column AG (criteria =1) fo each newly added worksheet and copy them accordingly to existing worksheets “1” until “18”. However, this is how I want it to go: The filtered contents of 1st newly added worksheet gets copied to sheet “1”, the 2nd newly added worksheets filtered contents get copied to sheet “2”, and so on until the 18th newly added worksheet filtered contents gets copied onto sheet “18”.
Appreciate if you could help me write a code based on this.thanks a lot!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi guys,
I have a macro code that opens up excel files and adds them up to an existing workbook (that is already open) with already 19 worksheets (worksheet names as follows: “result”, “1”, “2”, “3”,.. until “18”).
Now after adding the new worksheets (18 total as well with varying sheet names, and is always changing), I will filter the column AG (criteria =1) fo each newly added worksheet and copy them accordingly to existing worksheets “1” until “18”. However, this is how I want it to go: The filtered contents of 1st newly added worksheet gets copied to sheet “1”, the 2nd newly added worksheets filtered contents get copied to sheet “2”, and so on until the 18th newly added worksheet filtered contents gets copied onto sheet “18”.
Appreciate if you could help me write a code based on this.thanks a lot!
 
Upvote 0
I just increased the font size of your original post so I could read it. You used a very small font size. I have no answer at this point
HI there ,thanks for taking time to reply. However I could not see the script you provided for some reason.
 
Upvote 0
Hi, I just want to share the answer i got form another forum. With minor modifications on actual filter range, it worked perfectly. Here it is:


Sub sbUpdatedSheets()
Dim i, NumSheets As Integer
Dim lastRow As Long
NumSheets = 18
For i = 1 To NumSheets
'Filter the new source sheet and copy the content
Sheets(NumSheets + 1 + i).Activate
ActiveSheet.Range("$A$1:$CW$1159").AutoFilter Field:=29, Criteria1:="1"
ActiveSheet.Range("$A$1:$CW$1159").Copy
'Find the last free row in destination sheet and paste
Sheets(i + 1).Activate
lastRow = ActiveSheet.Cells.SpecialCells(xlLastCell).Row
Do While Application.CountA(ActiveSheet.Rows(lastRow)) = 0 And lastRow <> 1
lastRow = lastRow - 1
Loop
Range("A" & lastRow).Select
ActiveSheet.Paste

Next

ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
Sheets("result").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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