Create new worksheet for each vendor

i8ur4re

Board Regular
Joined
Mar 1, 2015
Messages
97
Hi,

I have an excel sheet that has about 5000+ Sku's from over 150+ vendors, my excel sheet has a vendor column ( C ), I am going throught this manually which has taken me days to copy paste each vendor in a worksheet.

I am 5 hours in and realized i did about 50%, anyway i can automate this with a code or formula?

Thank you
 

Some videos you may like

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,538
Office Version
365
Platform
Windows
How about
Code:
Sub i8ur4re()
   Dim Cl As Range
   Dim Ws As Worksheet
   Dim Ky As Variant
   
   Set Ws = ActiveSheet
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws.Range("C2", Ws.Range("C" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Empty
      Next Cl
      For Each Ky In .keys
         Ws.Range("A1:Z1").AutoFilter 3, Ky
         Sheets.Add(, Sheets(Sheets.Count)).Name = Ky
         Ws.AutoFilter.Range.Copy Range("A1")
      Next Ky
      Ws.AutoFilterMode = False
   End With
End Sub
 

i8ur4re

Board Regular
Joined
Mar 1, 2015
Messages
97
How about
Code:
Sub i8ur4re()
   Dim Cl As Range
   Dim Ws As Worksheet
   Dim Ky As Variant
   
   Set Ws = ActiveSheet
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws.Range("C2", Ws.Range("C" & Rows.Count).End(xlUp))
         .Item(Cl.Value) = Empty
      Next Cl
      For Each Ky In .keys
         Ws.Range("A1:Z1").AutoFilter 3, Ky
         Sheets.Add(, Sheets(Sheets.Count)).Name = Ky
         Ws.AutoFilter.Range.Copy Range("A1")
      Next Ky
      Ws.AutoFilterMode = False
   End With
End Sub
I got a run-time error 1004:
Application-define or oobject-defined error.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,538
Office Version
365
Platform
Windows
What line gave that error?
 

i8ur4re

Board Regular
Joined
Mar 1, 2015
Messages
97
I got a run-time error 1004:
Application-define or oobject-defined error.
I fixed that error, but i did get a Run-Time error 1004

You typed an invalid name for a sheet or chart. Make sure that:
The name that you type does not exceed 31 characters.
The name does not contain any of the following characters: \ / ?* [ or ]
You did not leave the name blank.

I did notice some vendor names might surpass the 31 characters, anyway around this, maybe trim at 30 characters?

This line gave the error:

Sheets.Add(, Sheets(Sheets.Count)).Name = Ky
 
Last edited:

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,538
Office Version
365
Platform
Windows
You could use
Code:
Sheets.Add(, Sheets(Sheets.Count)).Name = Left(Ky,30)
as long as the vendor names don't contain any illegal characters.
 

i8ur4re

Board Regular
Joined
Mar 1, 2015
Messages
97
You could use
Code:
Sheets.Add(, Sheets(Sheets.Count)).Name = Left(Ky,30)
as long as the vendor names don't contain any illegal characters.
That worked, the last problem im facing is it creates the new worksheets but they are empty, any chance i can take all the content for that vendor and move it to the new worksheet? Its currently only taking the header.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,538
Office Version
365
Platform
Windows
Do you have any blank rows in the data?
 

i8ur4re

Board Regular
Joined
Mar 1, 2015
Messages
97
Do you have any blank rows in the data?
Yes, I do have a few empty rows or missing data, here is what 2 rows look like, this is the original, i managed to clean it up prior, but at this rate, i can go with the information below:

SkuDim.1Dim.2Dim.3Dim.4StoreDescriptionVendorDepartmentProduct NumberQTYAVLQOHSOLDCOMITQOOSOQTBPRECVTRANOTITADJMinMaxQROPLookupsDim.1 GroupDim.1 DescriptionDim.2 GroupDim.2 DescriptionDim.3 GroupDim.3 DescriptionDim.4 GroupDim.4 DescriptionIn Store LocationPriceListCostAvgCostBrandSeasonBin Picking#Tax1Tax2Tax3
8024True Terpenes .5ml Ceramic Cartridge WhiteTrue TerpenesExtraction191924830000025000-110000122000$0.99$0.80$0.80True TerpenesY
6258Cartridge Plastic Containers .5 ml ::$0.25Ypsilanti Oil CompanyExtraction1704231327000054000000-5631000$0.25$0.12$0.11$$$Y

<colgroup><col><col span="4"><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col><col span="2"><col><col><col><col span="3"></colgroup><tbody>
</tbody>
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
42,538
Office Version
365
Platform
Windows
Ok how about
Code:
Sub i8ur4re()
   Dim Cl As Range
   Dim Ws As Worksheet
   Dim Ky As Variant
   Dim UsdRws As Long
   
   Set Ws = ActiveSheet
   UsdRws = Ws.Range("C" & Rows.Count).End(xlUp).Row
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws.Range("C2:C" & UsdRws)
         .Item(Cl.Value) = Empty
      Next Cl
      For Each Ky In .keys
         Ws.Range("A1:Z" & UsdRws).AutoFilter 3, Ky
         Sheets.Add(, Sheets(Sheets.Count)).Name = Ky
         Ws.AutoFilter.Range.Copy Range("A1")
      Next Ky
      Ws.AutoFilterMode = False
   End With
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,102,134
Messages
5,484,935
Members
407,475
Latest member
Dix_Fix

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top