Mandeep,

Thanks for your response. I am getting the below error message   "Run Time 
error '9' "       "Subscript out of range "   on the line highlighted in 
yellow.








On Tuesday, January 5, 2016 at 8:05:41 AM UTC-5, Mandeep Baluja wrote:
>
> Check this out !! save this output file in a folder and result will come 
> in the same folder 
> https://www.facebook.com/groups/825221420889809/
>
>
> Regards, Mandeep baluja 
>
> Sub CreateSheetsDemo()
>     
>     Dim wb As Workbook
>     Dim wbtemp As Workbook
>     Dim Workrng As Range
>     Dim uniquename As Variant
>     Dim Dic As Object
>     Dim lr As Long: lr = Sheets("Order").Cells(Rows.Count, 4).End(xlUp).Row
>     mypath = ThisWorkbook.Path & "\"
>
>     Set wb = ThisWorkbook
>     Set Workrng = wb.Sheets("order").Range("A1:E" & lr)
>     Debug.Print Workrng.Address
>     Set Dic = CreateObject("Scripting.dictionary")
>     Set dic2 = CreateObject("Scripting.dictionary")
>     Set dic3 = CreateObject("Scripting.dictionary")
>     
>     For rownum = 2 To lr
>             If (Not Dic.Exists(Cells(rownum, 4).Value)) Then
>                    Dic.Add Cells(rownum, 4).Value, Cells(rownum, 5).Value
>             End If
>     Next
>         uniquename = Dic.keys
>     For i = LBound(uniquename) To UBound(uniquename)
>            Workrng.AutoFilter field:=4, Criteria1:=uniquename(i)
>            Set wbtemp = Workbooks.Add
>             Workrng.SpecialCells(xlCellTypeVisible).Copy
>             wbtemp.Sheets("Sheet1").Range("A1").PasteSpecial 
> Paste:=xlPasteAll
>             wbtemp.Sheets("Sheet1").Name = "Order"
>             'Calculation work
>              wbtemp.Sheets("Sheet2").Name = "Summary"
>              wbtemp.Sheets("Summary").Range("A1:B1").Merge
>              Debug.Print
>              wbtemp.Sheets("Summary").Range("A1").Value = uniquename(i) & 
> "   Employee id :" & Dic.Item(uniquename(i))
>              lr = wbtemp.Sheets("order").Cells(Rows.Count, 4).End(xlUp).Row
>           
> '---------------------------------------------------------------------------
>           For rownum = 2 To lr
>                 If (Not dic2.Exists(Cells(rownum, 2).Value)) Then
>                    dic2.Add Cells(rownum, 2).Value, 1
>                 Else
>                  dic2.Item(Cells(rownum, 2).Value) = 
> dic2.Item(Cells(rownum, 2).Value) + 1
>                 End If
>           Next
>                 Varout1 = dic2.keys
>              wbtemp.Sheets("Summary").Range("A3").Resize(UBound(Varout1) + 
> 1, 1) = Application.Transpose(Varout1)
>              
>            For Each cell In wbtemp.Sheets("Summary").Range("A2:a10")
>                 cell.Offset(0, 1) = dic2.Item(cell.Value)
>              Next
>              
>           
> '-------------------------------------------------------------------------------
>           For rownum = 2 To lr
>                 If (Not dic3.Exists(Cells(rownum, 3).Value)) Then
>                    dic3.Add Cells(rownum, 3).Value, 1
>                 Else
>                  dic3.Item(Cells(rownum, 3).Value) = 
> dic3.Item(Cells(rownum, 3).Value) + 1
>                 End If
>           Next
>                     
>             Varout2 = dic3.keys
>             wbtemp.Sheets("Summary").Range("A10").Resize(UBound(Varout2) + 
> 1, 1) = Application.Transpose(Varout2)
>                 
>             For Each cell In wbtemp.Sheets("Summary").Range("A10:a20")
>                 cell.Offset(0, 1) = dic3.Item(cell.Value)
>              Next
>           wbtemp.Sheets("Summary").Columns("A:I").AutoFit
>            wbtemp.SaveAs Filename:=mypath & uniquename(i)
>             wbtemp.Close
>             wb.Sheets("order").AutoFilterMode = False
>             
>             dic2.RemoveAll
>             dic3.RemoveAll
>             
>                
>     Next
>
> End Sub
>
>

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.

Reply via email to