Hello
Is it possible to have some code to take the data shown in the below example from sheet 1 and sheet 2 and order it altogather ina continpis list as in sheet with tthe extra columns added to the right? This si a mock up example but in reality there could be many tabs from which the data is taken. Any help is immensely appreciated.
thank you Darren.
Data from one tab and ordering in another
-
- 3StarLounger
- Posts: 313
- Joined: 04 May 2010, 15:18
Data from one tab and ordering in another
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data from one tab and ordering in another
Will the last sheet already be present, or should the code create it?
Best wishes,
Hans
Hans
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: Data from one tab and ordering in another
Hi,
Give this macro a try.
Attached is a working example of your file.
Give this macro a try.
Attached is a working example of your file.
Code: Select all
Sub CombineData()
Dim sh As Worksheet
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Combined").Delete
On Error GoTo 0
Sheets.Add Before:=Sheets(1)
ActiveSheet.name = "Combined"
For Each sh In Sheets
If sh.name <> "Combined" Then
sh.Range("A1").CurrentRegion.Offset(1).Copy Sheets("Combined").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next sh
Sheets(2).Rows(1).Copy
Sheets(1).Range("A1").PasteSpecial
Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1).Resize(, 3).Value = Array("Sum If", "Bulk Look Up", "Match")
Range("A1").Copy
Range("A1").CurrentRegion.Rows(1).PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
Columns.AutoFit
Range("A1").Select
Application.ScreenUpdating = True
End Sub
You do not have the required permissions to view the files attached to this post.
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- 3StarLounger
- Posts: 313
- Joined: 04 May 2010, 15:18
Re: Data from one tab and ordering in another
Thank you Hans
Yes the last tab will always be there.
Kind regards Darren.
Yes the last tab will always be there.
Kind regards Darren.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- 3StarLounger
- Posts: 313
- Joined: 04 May 2010, 15:18
Re: Data from one tab and ordering in another
Hi
Sorry, I had overlooked Rudi's solution, this does work. Thank you very much. However in the example that I provided, I omitted to include that there is an extra sheet from which I don't want the data combined, a little like in this example whereby sheet 1 is not to be included. It will always be the first sheet and it should laways be called sheet1 , though i can gaurantee. Is there a way to run the combine macro and not include sheet1?
Thank you Darren.
Sorry, I had overlooked Rudi's solution, this does work. Thank you very much. However in the example that I provided, I omitted to include that there is an extra sheet from which I don't want the data combined, a little like in this example whereby sheet 1 is not to be included. It will always be the first sheet and it should laways be called sheet1 , though i can gaurantee. Is there a way to run the combine macro and not include sheet1?
Thank you Darren.
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data from one tab and ordering in another
You could change the line
to
If you're not certain the name will always be "Sheet1", you can use
Code: Select all
If sh.name <> "Combined" Then
Code: Select all
If sh.name <> "Combined" And sh.name <> "Sheet1" Then
Code: Select all
Sub CombineData()
Dim sh As Worksheet
Dim strName As String
Application.ScreenUpdating = False
On Error Resume Next
Application.DisplayAlerts = False
Sheets("Combined").Delete
On Error GoTo 0
strName = Sheets(1).name
Sheets.Add Before:=Sheets(1)
ActiveSheet.name = "Combined"
For Each sh In Sheets
If sh.name <> "Combined" And sh.name <> strName Then
sh.Range("A1").CurrentRegion.Offset(1).Copy Sheets("Combined").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next sh
Sheets(2).Rows(1).Copy
Sheets(1).Range("A1").PasteSpecial
Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1).Resize(, 3).Value = Array("Sum If", "Bulk Look Up", "Match")
Range("A1").Copy
Range("A1").CurrentRegion.Rows(1).PasteSpecial Paste:=xlPasteFormats
Application.CutCopyMode = False
Columns.AutoFit
Range("A1").Select
Application.ScreenUpdating = True
End Sub
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 313
- Joined: 04 May 2010, 15:18
Re: Data from one tab and ordering in another
Hi Hans
thank you for this, is has not quite worked with the new sheet created not havin all the headings required column header, some have copied into the sheet1. Also it threw up the error "run-time error'1004' application defined or object defined error". I attach an example to show this. Any further guidance is most welcomed.
Thank you again.
thank you for this, is has not quite worked with the new sheet created not havin all the headings required column header, some have copied into the sheet1. Also it threw up the error "run-time error'1004' application defined or object defined error". I attach an example to show this. Any further guidance is most welcomed.
Thank you again.
You do not have the required permissions to view the files attached to this post.
-
- Administrator
- Posts: 78412
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: Data from one tab and ordering in another
Does the attached version work better for you?
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans
Hans
-
- 3StarLounger
- Posts: 313
- Joined: 04 May 2010, 15:18
Re: Data from one tab and ordering in another
Thanks Hans
that's great.
that's great.