Jagwarman
asked on
Move data to new sheets in Excel
I have a Static Data Sheet with Names of Countries in Column A [ this list will increase in time]
In the Raw Data Sheet in Column P are the names of countries.
If the countries in column P in the Raw Data Tab are in the Static Data table [in Sheet named Static Data] I need to create a new sheet, if one does not already exist.
I then need to copy the entire rows from the Raw Data tab onto the respective [named] Sheets and include the header row in each sheet.
So if Spain is in P10, P11, P12, P13 in the Raw Data Sheet, I need to copy both the header from the Raw Data Sheet and Rows 10,11,12,13 to the sheet named Spain
Rgonzo1971 provided me with the below code recently but unfortunately the user criteria changed.
Sub c2sheets()
Set SrcSheet = ActiveSheet
For Idx = 2 To Range("M2:M" & Range("M" & Rows.Count).End(xlUp).Row) .Count + 1
If SrcSheet.Range("M" & Idx).Value <> "" Then
Set DestSh = Worksheets.Add(, Worksheets(Worksheets.Coun t))
DestSh.Name = SrcSheet.Range("M" & Idx).Value
Idx2 = Idx
While SrcSheet.Range("M" & Idx).Offset(1) = SrcSheet.Range("M" & Idx)
Idx = Idx + 1
Wend
SrcSheet.Range("1:1").Copy DestSh.Range("1:1")
SrcSheet.Range(Idx & ":" & Idx2).Copy DestSh.Range("2:2")
End If
Next
End Sub
Thanks in advance
In the Raw Data Sheet in Column P are the names of countries.
If the countries in column P in the Raw Data Tab are in the Static Data table [in Sheet named Static Data] I need to create a new sheet, if one does not already exist.
I then need to copy the entire rows from the Raw Data tab onto the respective [named] Sheets and include the header row in each sheet.
So if Spain is in P10, P11, P12, P13 in the Raw Data Sheet, I need to copy both the header from the Raw Data Sheet and Rows 10,11,12,13 to the sheet named Spain
Rgonzo1971 provided me with the below code recently but unfortunately the user criteria changed.
Sub c2sheets()
Set SrcSheet = ActiveSheet
For Idx = 2 To Range("M2:M" & Range("M" & Rows.Count).End(xlUp).Row)
If SrcSheet.Range("M" & Idx).Value <> "" Then
Set DestSh = Worksheets.Add(, Worksheets(Worksheets.Coun
DestSh.Name = SrcSheet.Range("M" & Idx).Value
Idx2 = Idx
While SrcSheet.Range("M" & Idx).Offset(1) = SrcSheet.Range("M" & Idx)
Idx = Idx + 1
Wend
SrcSheet.Range("1:1").Copy
SrcSheet.Range(Idx & ":" & Idx2).Copy DestSh.Range("2:2")
End If
Next
End Sub
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Rgonzo
yours does not work. my request was...
I have a Static Data Sheet with Names of Countries in Column A [ this list will increase in time]
In the Raw Data Sheet in Column P are the names of countries.
If the countries in column P in the Raw Data Tab are in the Static Data table [in Sheet named Static Data] I need to create a new sheet, if one does not already exist.
but yours does not appear to look at the Static Data Sheet and it does not appear to create separate sheets per country
Thanks
yours does not work. my request was...
I have a Static Data Sheet with Names of Countries in Column A [ this list will increase in time]
In the Raw Data Sheet in Column P are the names of countries.
If the countries in column P in the Raw Data Tab are in the Static Data table [in Sheet named Static Data] I need to create a new sheet, if one does not already exist.
but yours does not appear to look at the Static Data Sheet and it does not appear to create separate sheets per country
Thanks
Did you try mine ??
gowflow
gowflow
ASKER
Just testing it gowflow
ASKER
That does it for me Gowflow thanks
Your welcome !
gowflow
gowflow
pls try
Open in new window
EDIT correctedRegards