macro to split excel work book

message2sagar

New Member
Joined
Aug 27, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hi,
Am pretty new to macros and i would need a macro to split workbook into different tabs based on unique field/column, however my problem is i have first few rows which are headers in the main tab.

my request is
1. the first few rows to be copied in all the tabs while splitting the main tab as those headers will be same for all the workbooks
2. Macro should not filter on row1 instead it should filter on row 8 and take unique based on column F

is this possible to do so. Please help
 

Attachments

  • Capture.PNG
    Capture.PNG
    20.7 KB · Views: 8

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi and welcome to MrExcel

Try this:

VBA Code:
Sub create_worksheets()
  Dim c As Range, sh As Worksheet
  Dim ky As Variant, lr As Long
  
  Set sh = Sheets("Master")
  lr = sh.Range("F" & Rows.Count).End(3).Row
  
  With CreateObject("scripting.dictionary")
    For Each c In sh.Range("F9:F" & lr)
      .Item(c.Value) = Empty
    Next c
    For Each ky In .Keys
      sh.Range("F8").AutoFilter 1, ky
      Sheets.Add(, Sheets(Sheets.Count)).Name = ky
      sh.Rows("1:" & lr).Copy Range("A1")
    Next ky
  End With
  
  sh.Select
  sh.ShowAllData
End Sub
 
Upvote 0
Hey, Thanks for looking into it, i just copied and pasted into new module and ran the macro.

It says Run-time error '9':
Subscript out of range

anything i should be adding to this macro ? Please adivse.
 
Upvote 0
If you press the "debug" button on which line of the macro it stopped.
Also if you can tell me the values that each variable contains at the time of the error?
 
Upvote 0

Forum statistics

Threads
1,214,619
Messages
6,120,550
Members
448,970
Latest member
kennimack

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