Copy data to multiple sheets when store # changes & Name sheet

bcurrey

Board Regular
Joined
Aug 11, 2011
Messages
110
Office Version
  1. 365
Platform
  1. MacOS
Summary: I have a spreadsheet with multiple store performance metrics on it and need to break them out to separate tabs.

The table has data in columns A thru AC. The number of rows can vary.

I've sorted the table by column B (Store #).

These are the steps I can't figure out:
  1. I want to copy each stores data to a new sheet (based on column B). I want the headers to be copied to each tab as well that are in row 1.
  2. (this is my big hurdle) Once each sheet is created, I want the name of the sheet to become the store number

Would appreciate any guidance. I can't find any threads or instructions on doing exactly what I need. Thanks for the help!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Try this, change "Data" for the name of your sheet.

VBA Code:
Sub create_worksheets()
  Dim c As Range, sh As Worksheet, ky As Variant
  
  Application.ScreenUpdating = False
  Set sh = Sheets("Data")
  With CreateObject("scripting.dictionary")
    For Each c In sh.Range("B2", sh.Range("B" & Rows.Count).End(xlUp))
      If c.Value <> "" Then .Item(c.Value) = Empty
    Next c
    For Each ky In .Keys
      sh.Range("A1").AutoFilter 2, ky
      Sheets.Add(, Sheets(Sheets.Count)).Name = ky
      ActiveSheet.Name = ky
      sh.AutoFilter.Range.EntireRow.Copy Range("A1")
    Next ky
  End With
  sh.Select
  sh.ShowAllData
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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