Copy and paste data into new tab, keep format and change tab names

CRMTHB

New Member
Joined
Mar 12, 2019
Messages
13
Hi,


I have headers in row 1, with data underneath. For every change in column A, I want the data (plus the headers) copied and pasted into a new tab. I then want that tab to be named the same as the data then in cell A2 of the new tabs.


So, if there are 7 rows with "Bananas", I want those 7 moved to a new tab called "Bananas". The next 3 which say "Apples" to be called Apples etc.


Each tab would have the headers, and would have the same formatting used in the original sheet.

If this is possible, any help would be appreciated

Thanks
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi & welcome to MrExcel
How about
Code:
Sub CRMTHB()
   Dim Ws As Worksheet
   Dim Cl As Range
   Dim Ky As Variant
   
   Set Ws = Sheets("Pcode")
   If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws.Range("A2", Ws.Range("A" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Empty
      Next Cl
      For Each Ky In .Keys
         Ws.Copy , Sheets(Sheets.Count)
         With ActiveSheet
            .Name = Ky
            .Range("A1").AutoFilter 1, "<>" & Ky
            .AutoFilter.Range.Offset(1).EntireRow.Delete
            .AutoFilterMode = False
         End With
      Next Ky
   End With
End Sub
 
Upvote 0
Hi Fluff, thank you for coming back to me.

The code works really well except some of the names are more than 31 characters, meaning it's too long for the tabs. Is there code that would limit the name of the tabs to 30 characters?

Thanks
Matt
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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