kweaver
Well-known Member
- Joined
- May 12, 2009
- Messages
- 2,940
- Office Version
- 365
Either Dante or someone else...I'm trying to work through this perfect macro Dante wrote for me but there are many things I don't understand in my novice VBA.
The main thing is the scripting dictionary. I've been trying to read about this but it's not sinking in.
I don't understand, for one, how the "c" is created in the first FOR block, and where does ".Item" come from?
If someone has time to help me understand this, I'm really appreciative.
The main thing is the scripting dictionary. I've been trying to read about this but it's not sinking in.
I don't understand, for one, how the "c" is created in the first FOR block, and where does ".Item" come from?
If someone has time to help me understand this, I'm really appreciative.
Rich (BB code):
Sub Test()
Dim sh As Worksheet, c As Range, ky As Variant, wb As Workbook, wPath As String, lr As Long
Application.SheetsInNewWorkbook = 1
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set sh = Sheets("Reformatted")
wPath = "C:\trabajo\books\"
If sh.AutoFilterMode Then sh.AutoFilterMode = False
lr = sh.Range("P" & Rows.Count).End(xlUp).Row
With CreateObject("scripting.dictionary")
For Each c In sh.Range("P2:P" & lr)
.Item(c.Value) = Empty
Next
For Each ky In .Keys
sh.Range("A1").AutoFilter 16, ky
Set wb = Workbooks.Add
sh.AutoFilter.Range.Range("A2:O" & lr).Copy Range("A1") 'Change 2 to 1 if you also want to copy the header.
wb.SaveAs wPath & ky
wb.Close False
Next
End With
sh.ShowAllData
End Sub