VBA Help

Kyosti

Board Regular
Joined
Jun 2, 2008
Messages
90
I have tried to adjust a VBA Code that was built for me by @Fluff and I thought I was close to getting it to work, but I was mistaken.

Sub Kyosti()
Dim Cl As Range
Dim Ws As Worksheet
Dim Ky As Variant

Set Ws = Sheets("Data")
With CreateObject("scripting.dictionary")
For Each Cl In Ws.Range("O2", Ws.Range("O" & Rows.Count).End(xlUp))
.Item(Cl.Value) = Empty
Next Cl
For Each Ky In .Keys
Ws.Range("A1:O1").AutoFilter 15, Ky
Sheets.Add(, Sheets(Sheets.Count)).Name = Ky
Ws.AutoFilter.Range.SpecialCells(xlVisible).EntireRow.Copy Range("A1")
Next Ky
Ws.AutoFilterMode = False
End With
End Sub

The original code was written for a different file but I am attempting to use the same logic on the file outlined below



Agent #Agency NameAgent First nameAgent Last nameAgency Location AddressAgency Location CityAgency Location CodeAgency Location StateAgency Location Zip CodeAgency Termination DateAgency StatusNew OwnerSale DateEntry DateSale TypeRegionDaysPolicy Count
NJ Region
NY Region
FL Region

<colgroup><col width="64" span="18" style="width:48pt"> </colgroup><tbody>
</tbody>


The new logic would essentially create a new tab for every region with the filtered information. I made adjustments to the original code to match the new file, but I get a debug at:

Sheets.Add(, Sheets(Sheets.Count)).Name = Ky

Can anyone help me understand the language or what it is doing so I can adjust accordingly!? Any help is greatly appreciated.
 
So it seems that the error was being caused by N/A Values. Once I reconciled for that it works just fine. But it is not creating the tabs at the end or in Alphabetical order. I thought that was part of the code originally. Any suggestions??
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
.
"But it is not creating the tabs at the end or in Alphabetical order."

At the end of what ?

The tabs are created in the order found beginning on Row #2 and moving down. Arranging in alphabetical order requires additional code.


In your workbook ... how many tabs are being created ?
 
Last edited:
Upvote 0
The file has 5 starting tabs, and the macro creates 14-15 new tabs. In my other code on the older file it is built in to create the new tabs at the end and in alphabetical order. I just thought the code I grabbed had that portion of the code included.
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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