Forum

VBA to copy all wor...
 
Notifications
Clear all

VBA to copy all worksheets into one

8 Posts
2 Users
0 Reactions
64 Views
(@alinhart)
Posts: 39
Trusted Member
Topic starter
 

Hello

Good afternoon.

I would love some help writing a macro that does the following:

Copy’s all worksheets into one “Summary Tab”, with the exception of the Drop List tab. I will be adding new tabs each week, so I will have re-run this macro weekly as well.  I would like for it to replace the old information.

All the headers are the same, so I only need the header columns listed once at the top of the list.

Any help would be greatly appreciated.

 Thanks

Amy

 
Posted : 04/10/2018 5:18 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Amy

Give this a try.

Please note that for any additional sheet to be added and merged, the sheet's name must contain the text "Scrap Report"

The macro will search thru all sheets and will only merge those sheet names containing the text "Scrap Report".

The macro will clear the Summary Tab data (excluding the header) before merging.

Hope this helps.

Sunny

 
Posted : 05/10/2018 12:17 am
(@alinhart)
Posts: 39
Trusted Member
Topic starter
 

Sunny

Wow! Thank you so much.  This is awesome.  This will save me so much time.

I have a question on the formula?

 With this, does this mean something has to be in column B for it to pull over onto the summary tab?

Find the last row with data

            LastSrc = ws.Cells(Rows.Count, "B").End(xlUp).Row 'Weekly sheet

Also, can you explain this code as well?  What does the “A” do?

CopyRng.Copy

                With DestSh.Cells(LastTgt + 1, "A")

I’m trying to learn VBA, put it’s a struggle.

Thank you again for taking the time to help me with this.

Sincerely

Amy

 
Posted : 05/10/2018 8:12 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Amy

Glad you like the macro.

The code LastSrc = ws.Cells(Rows.Count, "B").End(xlUp).Row search for the last row with data in column B.

You can use any column of your choice but make sure that it does not have any blanks.

I did not choose column A in your example as I noticed that in your Scrap Report Week 1 sheet, my macro would have given me 3 as the last row instead of 4 due to the blank in cell A4.

In the code With DestSh.Cells(LastTgt + 1, "A")  , A is the column as the syntax is CELLS(row,column). Both row and column can be a number but column can also be an alphabet like this case.

The code  If LastSrc >= StartTgt checks to see if the last row is the same or more than the start row which I set to 3 in your example.

If it is more than or equal to 3 then it must contain data and the data will be copied, else that sheet will be ignored.

Hope this explanation is clear enough.

Sunny

 
Posted : 05/10/2018 7:17 pm
(@alinhart)
Posts: 39
Trusted Member
Topic starter
 

Sunny

Thanks again.  I have one more thing I would like to add to the macro, if possible? On the Summary Tab, is there a way to highlight the cell in the RGA # column (K) if the cell is blank,  but only if the Disposition column (J) is Vendor Credit / Return.  This way I know I have to get a RGA from the customer. 

Thanks so much

Amy

 
Posted : 22/10/2018 7:18 pm
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Amy

Not sure if your "blank" means a totally blank cell or 0 (or something else).

I set it to check for blank cell .i.e. = ""

You can change it to = 0 if you like.

It will highlight the cell in yellow.

Hope this helps.

Sunny

 
Posted : 22/10/2018 8:37 pm
(@alinhart)
Posts: 39
Trusted Member
Topic starter
 

Sunny

You are amazing!  Thank you so much!   

Amy

 
Posted : 23/10/2018 8:23 am
(@sunnykow)
Posts: 1417
Noble Member
 

Hi Amy

Thanks for your feedback.

Happy to know it is working for you.

Sunny

 
Posted : 23/10/2018 6:47 pm
Share: