Re: $$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-06 Thread Kalyan Dutta
Mandeep,

Yes... It worked... Both the output files are showing Employee Id. Thank
you so much for your help. I really appreciate your time,effort and
attitude to help others.

Regards,

On Wed, Jan 6, 2016 at 5:07 AM, Mandeep Baluja 
wrote:

>  Let me know !!
>
> 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
> Debug.Print Cells(ROWNUM, 5)
>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 Dic.Item(uniquename(i))
> 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 

Re: $$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-06 Thread Kalyan Dutta
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 
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 

Re: $$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-06 Thread Mandeep Baluja
 Let me know !!

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
Debug.Print Cells(ROWNUM, 5)
   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 Dic.Item(uniquename(i))
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 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 

Re: $$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-06 Thread Mandeep Baluja
Glad to help !!! 

Regards,
Mandeep baluja


>

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


$$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-05 Thread Mandeep Baluja
Did you run the code in input file ? Have you tried debugging of code step 
by step ? Why paste:=xlpasteall is deleted ? I have not received this error 
while  running this code something u are doing wrong unintentionally. 

Regards,
Mandeep 

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


Re: $$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-05 Thread Mandeep Baluja

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


Re: $$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-05 Thread Kalyan Dutta
Mandeep

I added line #31 (wbtemp.Sheets.Add) BECAUSE MY EXCEL BOOK DOES NOT CREATES
"SHEET2" AUTOMATICALLY. When I added this line , The code runs without any
error. But Summary Tab is incorrect. See the attached output file.


Please provide some suggestions.

On Tue, Jan 5, 2016 at 12:07 PM, Mandeep Baluja 
wrote:

> Did you run the code in input file ? Have you tried debugging of code step
> by step ? Why paste:=xlpasteall is deleted ? I have not received this error
> while  running this code something u are doing wrong unintentionally.
>
> Regards,
> Mandeep
>
> --
> 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.


Craig Smith.xlsx
Description: MS-Excel 2007 spreadsheet


input.xlsm
Description: application/vnd.ms-excel.sheet.macroenabled.12


Kelly Davis.xlsx
Description: MS-Excel 2007 spreadsheet


$$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-05 Thread Mandeep Baluja
Check this out !! and let me know 


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.


$$Excel-Macros$$ Re: Create Multiple Excel Files from One file

2016-01-05 Thread Kalyan Dutta


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