Mandeep,

Your code worked except small glitch. The output file of Craig Smith
showing employee Id at the top of the file ,
whereas, Kelly Davis output file missing employee Id. See the attached file.



On Wed, Jan 6, 2016 at 12:18 AM, Mandeep Baluja <rockerna...@gmail.com>
wrote:

> Try This code !!
>>
>
> 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 & "\"
>
>     Application.ScreenUpdating = False
>     Application.DisplayAlerts = False
>
>     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")
>     Dic.RemoveAll
>     dic2.RemoveAll
>     dic3.RemoveAll
>     ActiveSheet.AutoFilterMode = False
>     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
>             Set ws = wbtemp.Sheets.Add ' ADDED THIS LINE BECAUSE MY EXCEL
> BOOK DOES NOT CREATES "SHEET2" AUTOMATICALLY
>             ws.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(wbtemp.Sheets("order").Cells(rownum,
> 2).Value)) Then
>                    dic2.Add wbtemp.Sheets("order").Cells(rownum, 2).Value,
> 1
>                 Else
>                  dic2.Item(wbtemp.Sheets("order").Cells(rownum, 2).Value)
> = dic2.Item(wbtemp.Sheets("order").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(wbtemp.Sheets("order").Cells(rownum,
> 3).Value)) Then
>                    dic3.Add wbtemp.Sheets("order").Cells(rownum, 3).Value,
> 1
>                 Else
>                  dic3.Item(wbtemp.Sheets("order").Cells(rownum, 3).Value)
> = dic3.Item(wbtemp.Sheets("order").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
>             Dic.RemoveAll
>             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 a topic in the
> Google Groups "MS EXCEL AND VBA MACROS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/excel-macros/hwUIzChL0Hc/unsubscribe.
> To unsubscribe from this group and all its topics, 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.
>

-- 
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.

Attachment: Craig Smith.xlsx
Description: MS-Excel 2007 spreadsheet

Attachment: Kelly Davis.xlsx
Description: MS-Excel 2007 spreadsheet

Reply via email to