Loop to create newsheets for each owner & copy, paste data of each owner into the new sheet

suresh7860

New Member
Joined
Jul 18, 2015
Messages
48
HI Experts

Good Morning!!

I am have created a macro to consolidate 3 different reports to combine score, criteria and owner details by using combo and convert the report into pdf which is working fine but now requirement has changed that i should report each owner data into different tab and convert it but i am not able to get the details like how to export all the rows of each owner into different tab and rename the tabs as per the owner as i am very poor with vba loops. If any of the experts can help me to export data of each owner for a particular sheet and rename it with owner name and loop should run until the lastrow.

We don't have list of owners and number of rows, here it should create 3 sheets as we have 3 owners (Suresh, Sainath & Sanjay) and entire rows related to each owner should be moved to respective sheet and rename the sheets as Suresh, Sanjay & Sainath. I tried to research in google for this but didnt find anything suitable one whichever i got was creating muliple sheets as owner name will be listed many times and which as per my criteria we should have only one sheet for each owner name with his details.

Rows
Combo (A)
Owner (B)
Criteria(C)
Standard (D)
Achieved(E)
Total Score(F)
1
1001-100001-A001SureshA10080
2
1001-100001-A001SureshB5580
3
1001-100001-A001SureshC5580
4
1001-100001-A001SureshD10080
5
1001-100001-A001SureshE151580
6
1001-100001-A001SureshF101080
7
1001-100001-A001SureshG101080
8
1001-100001-A001SureshH101080
9
1001-100001-A001SureshI151580
10
1001-100001-A001SureshJ101080
11
1002-100002-A002SanjayA101085
12
1002-100002-A002SanjayB5585
13
1002-100002-A002SanjayC5585
14
1002-100002-A002SanjayD101085
15
1002-100002-A002SanjayE15085
16
1002-100002-A002SanjayF101085
17
1002-100002-A002SanjayG101085
18
1002-100002-A002SanjayH101085
19
1002-100002-A002SanjayI151585
20
1002-100002-A002SanjayJ101085
21
1003-100003-A003SainathA101095
22
1003-100003-A003SainathB5595
23
1003-100003-A003SainathC5095
24
1003-100003-A003SainathD101095
25
1003-100003-A003SainathE151595
26
1003-100003-A003SainathF101095
27
1003-100003-A003SainathG101095
28
1003-100003-A003SainathH101095
29
1003-100003-A003SainathI151595
30
1003-100003-A003SainathJ101095
31
1004-100004-A004SureshA101075
32
1004-100004-A004SureshB5575
33
1004-100004-A004SureshC5575
34
1004-100004-A004SureshD101075
35
1004-100004-A004SureshE151575
36
1004-100004-A004SureshF101075
37
1004-100004-A004SureshG101075
38
1004-100004-A004SureshH10075
39
1004-100004-A004SureshI15075
40
1004-100004-A004SureshJ101075
41
1005-100005-A005SanjayA101090
42
1005-100005-A005SanjayB5090
43
1005-100005-A005SanjayC5090
44
1005-100005-A005SanjayD101090
45
1005-100005-A005SanjayE151590
46
1005-100005-A005SanjayF101090
47
1005-100005-A005SanjayG101090
48
1005-100005-A005SanjayH101090
49
1005-100005-A005SanjayI151590
50
1005-100005-A005SanjayJ101090
51
1006-100006-A006SureshA101075
52
1006-100006-A006SureshB5575
53
1006-100006-A006SureshC5575
54
1006-100006-A006SureshD101075
55
1006-100006-A006SureshE151575
56
1006-100006-A006SureshF101075
57
1006-100006-A006SureshG101075
58
1006-100006-A006SureshH101075
59
1006-100006-A006SureshI15075
60
1006-100006-A006SureshJ10075
61
1007-100007-A007SainathA1010100
62
1007-100007-A007SainathB55100
63
1007-100007-A007SainathC55100
64
1007-100007-A007SainathD1010100
65
1007-100007-A007SainathE1515100
66
1007-100007-A007SainathF1010100
67
1007-100007-A007SainathG1010100
68
1007-100007-A007SainathH1010100
69
1007-100007-A007SainathI1515100
70
1007-100007-A007SainathJ1010100

<tbody>
</tbody>
Thanks for your time & help!

Regards
Suresh7860
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
For Input Data in Sheet1, Try this:

Code:
Sub Suresh()
Dim i       As Long
Dim rng     As Range
Dim Q       As Variant
Dim dict    As Object
Dim ar      As Variant

Set rng = Sheets("Sheet1").Range("B2:B" & Cells(Rows.Count, 1).End(xlUp).Row)
Set dict = CreateObject("scripting.dictionary")

With dict
For Each cell In rng
    If Not .exists(cell.Value) Then
        i = 1
        ReDim ar(1 To Application.CountIf(rng, cell.Value), 1 To 6)
        ar(i, 1) = cell.Offset(, -1): ar(i, 2) = cell.Value: ar(i, 3) = cell.Offset(, 1)
        ar(i, 4) = cell.Offset(, 2): ar(i, 5) = cell.Offset(, 3): ar(i, 6) = cell.Offset(, 4)
        .Add cell.Value, Array(ar, i)
    Else
        Q = .Item(cell.Value)
        Q(1) = Q(1) + 1
        Q(0)(Q(1), 1) = cell.Offset(, -1): Q(0)(Q(1), 2) = cell.Value: Q(0)(Q(1), 3) = cell.Offset(, 1)
        Q(0)(Q(1), 4) = cell.Offset(, 2): Q(0)(Q(1), 5) = cell.Offset(, 3): Q(0)(Q(1), 6) = cell.Offset(, 4)
        .Item(cell.Value) = Q
    End If
Next

For Each k In .keys
    Worksheets.Add().Name = k
    Sheets(k).Range("A1:F1") = Array("Combo(A)", "Owner(B)", "Criteria (C)", "Standard (D)", "Achieved (E)", "Total Score (F)")
    Sheets(k).Range("A2").Resize(.Item(k)(1), 6) = .Item(k)(0)
    Sheets(k).Columns.AutoFit
Next

End With
End Sub

Regards,
Ombir
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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