Split the result by sum in various sheets

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,362
Office Version
  1. 2010
Using Excel 2010

Hello,

I have sheet “Result 100 to 114” in which I have results with sum in-between 100 to 114. Than I have 14 sheets with name 100-101-102 till 114, I want a VBA that which can copy only values of each sum in there corresponding sheet 100 in 100 sheet, 101 in 101 sheets here is example of 2 sums 100 and 101

Note: please I want a macro which can be used in Excel 2000 also.
Data sheet.......
LotoTurf.xls
ABCDEFGHIJ
1YEARDATEn1n2n3n4n5n6EM1Sum
2YEARDATEn1n2n3n4n5n6EM1Sum
3YEARDATEn1n2n3n4n5n6EM1Sum
4YEARDATEn1n2n3n4n5n6EM1Sum
5YEARDATEn1n2n3n4n5n6EM1Sum
6200622/01/200681217212330111
7200626/02/20061518262731108
8200605/03/2006101117182426106
9200619/03/200671018222730114
10200611/06/200631015202528101
11200616/07/20067816192830108
12200620/08/2006131617192026111
13200624/09/20061718212429100
14200622/10/200621218212231106
15200721/06/200761619222427114
16200730/06/20072913252630105
17200707/07/20071618242627102
18200719/07/200721119212324100
19200721/07/200761920212223111
20200726/07/20076910252628104
21200712/08/2007101217192527110
22200716/09/200791112202530107
23200723/09/200751718212326110
24200730/09/200761012202431103
25200711/11/2007111318212427114
26200718/11/20072513252729101
27200702/12/20072920222325101
28200709/12/200721320232629113
29200828/02/200871115222426105
30200802/03/200811213242529104
31200815/05/20082316252728101
32200810/07/200841112222526100
33200812/07/200871516182031107
34200817/07/200821016192430101
35200815/08/20085716192231100
36200824/08/20084920222729111
37200814/09/200841319202425105
38200821/09/2008111216172731114
39200823/11/200851019202231107
40200911/01/20094919232628109
41200901/02/200931314192526100
42200922/02/200971316172227102
43200903/05/200981015181930100
44200921/06/20096714212430102
45200920/08/200951318212226105
46200915/11/20094520262829112
47201003/01/20101222232430102
48201007/02/20107913192529102
49201019/03/201091317192024102
50201016/05/20102918212527102
51201020/06/2010101213212630112
52201022/07/20104517222728103
53201017/09/20101821232425102
54201019/09/20103919232830112
55201026/12/20103518252627104
56201109/01/2011111316202527112
57201120/02/2011678262731105
58201122/04/2011101516202526112
59201127/05/201131115232830110
60201123/06/2011111213162731110
61201204/03/201291213162831109
62201208/04/201271417182528109
63201329/03/20134712272930109
64201325/07/201311019242630110
65201413/04/201481517192031110
66201420/06/201411011273031110
Result 100 To 114


Example....copy value expected filtered sum of100 here
LotoTurf.xls
ABCDEFGHIJ
1YEARDATEn1n2n3n4n5n6EM1Sum
2YEARDATEn1n2n3n4n5n6EM1Sum
3YEARDATEn1n2n3n4n5n6EM1Sum
4YEARDATEn1n2n3n4n5n6EM1Sum
5YEARDATEn1n2n3n4n5n6EM1Sum
6200624/09/20061718212429100
7200719/07/200721119212324100
8200810/07/200841112222526100
9200815/08/20085716192231100
10200901/02/200931314192526100
11200903/05/200981015181930100
12
13
100


Example....copy value expected filtered sum of100 here
LotoTurf.xls
ABCDEFGHIJ
1YEARDATEn1n2n3n4n5n6EM1Sum
2YEARDATEn1n2n3n4n5n6EM1Sum
3YEARDATEn1n2n3n4n5n6EM1Sum
4YEARDATEn1n2n3n4n5n6EM1Sum
5YEARDATEn1n2n3n4n5n6EM1Sum
6200611/06/200631015202528101
7200718/11/20072513252729101
8200702/12/20072920222325101
9200815/05/20082316252728101
10200817/07/200821016192430101
11
12
101


Regards,
Moti
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try this:
VBA Code:
Sub mtll()
Dim sh As Worksheet, c As Range, r As Range, d As Object, k
    Set d = CreateObject("Scripting.Dictionary")
    Set sh = ActiveWorkbook.Worksheets("Result 100 to 114")
    With sh
        If .FilterMode Then .ShowAllData
        Set r = .UsedRange
        With d
            For Each c In Range("J6:J" & Cells(6, 10).End(4).Row)
                .Item(c.Value) = c.Value
            Next c
            
            For Each k In .keys
                r.AutoFilter Field:=10, Criteria1:=k
                r.SpecialCells(xlCellTypeVisible).Copy
                ActiveWorkbook.Worksheets(CStr(k)).Paste
            Next k
        End With
        .ShowAllData
    End With
End Sub
 
Upvote 0
Try this:
VBA Code:
Sub mtll()
Dim sh As Worksheet, c As Range, r As Range, d As Object, k
    Set d = CreateObject("Scripting.Dictionary")
    Set sh = ActiveWorkbook.Worksheets("Result 100 to 114")
    With sh
        If .FilterMode Then .ShowAllData
        Set r = .UsedRange
        With d
            For Each c In Range("J6:J" & Cells(6, 10).End(4).Row)
                .Item(c.Value) = c.Value
            Next c
           
            For Each k In .keys
                r.AutoFilter Field:=10, Criteria1:=k
                r.SpecialCells(xlCellTypeVisible).Copy
                ActiveWorkbook.Worksheets(CStr(k)).Paste
            Next k
        End With
        .ShowAllData
    End With
End Sub
@LazyBug, VBA is not working correctly it deletes headers and copy any ware in sheet apart of that if I run again it keeps duplicating data it must has to past A6:j6 below.

Please see the results below....
LotoTurf.xls
ABCDEFGHIJKLM
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16YEARDATEn1n2n3n4n5n6EM1Sum
17200624/09/20061718212429100
18200719/07/200721119212324100
19200810/07/200841112222526100
20200815/08/20085716192231100
21200901/02/200931314192526100
22200903/05/200981015181930100
23
24
25
26
27
100


LotoTurf.xls
ABCDEFGHIJ
1YEARDATEn1n2n3n4n5n6EM1Sum
2200611/06/200631015202528101
3200718/11/20072513252729101
4200702/12/20072920222325101
5200815/05/20082316252728101
6200817/07/200821016192430101
7200718/11/20072513252729101
8200702/12/20072920222325101
9200815/05/20082316252728101
10200817/07/200821016192430101
11
101


Regards,
Moti
 
Upvote 0
I copied the data you gave as an example, and the code works as you said in the #1 post: it copies the data for each of the amounts with the headers in column J to an empty sheet with the corresponding name. Did I misunderstand the challenge?
 
Upvote 0
I copied the data you gave as an example, and the code works as you said in the #1 post: it copies the data for each of the amounts with the headers in column J to an empty sheet with the corresponding name. Did I misunderstand the challenge?
Hello LazyBug, let me explain and make the example sheet simpler with sums 100 & 101, data sheet “Result 100 to 114” has 5 header rows, data start from the row 6 below. And also I got 2 sheet named 100 & 101 already have 5 row header I want data must be copied and paste in these sheets from row 6 to below.(I do not have 100 & 101 sheets empty).

Secondly before running the macro you select for example cell D6 in sheet 100 & select any cell you want in the sheet 101 and come back to data sheet “Result 100 to 114” and run the macro see what happen. It pastes data within selected cells.

Here is how my sheets look like. Please can you check it?
Data sheet....
LotoTurf.xls
ABCDEFGHIJ
1YEARDATEn1n2n3n4n5n6EM1Sum
2YEARDATEn1n2n3n4n5n6EM1Sum
3YEARDATEn1n2n3n4n5n6EM1Sum
4YEARDATEn1n2n3n4n5n6EM1Sum
5YEARDATEn1n2n3n4n5n6EM1Sum
6200611/06/200631015202528101
7200624/09/20061718212429100
8200719/07/200721119212324100
9200718/11/20072513252729101
10200702/12/20072920222325101
11200815/05/20082316252728101
12200810/07/200841112222526100
13200817/07/200821016192430101
14200815/08/20085716192231100
15200901/02/200931314192526100
16200903/05/200981015181930100
17
18
19
20
Result 100 To 114


Sheet100...
LotoTurf.xls
ABCDEFGHIJ
1YEARDATEn1n2n3n4n5n6EM1Sum
2YEARDATEn1n2n3n4n5n6EM1Sum
3YEARDATEn1n2n3n4n5n6EM1Sum
4YEARDATEn1n2n3n4n5n6EM1Sum
5YEARDATEn1n2n3n4n5n6EM1Sum
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
101


Sheet 101....
LotoTurf.xls
ABCDEFGHIJ
1YEARDATEn1n2n3n4n5n6EM1Sum
2YEARDATEn1n2n3n4n5n6EM1Sum
3YEARDATEn1n2n3n4n5n6EM1Sum
4YEARDATEn1n2n3n4n5n6EM1Sum
5YEARDATEn1n2n3n4n5n6EM1Sum
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
101



Regards,
Moti
 
Upvote 0
This is pretty much what @LazyBug suggested, with just a couple of minor tweaks. Please try it on a copy of your workbook:
VBA Code:
Option Explicit
Sub motilulla()
    Dim ws As Worksheet
    Set ws = Worksheets("Result 100 to 114")
    Dim d As Object, c As Range, i As Long, a, b
    Set d = CreateObject("scripting.dictionary")
    a = ws.Range("J6", ws.Cells(Rows.Count, "J").End(xlUp))
    
    With ws
        With d
            For i = 1 To UBound(a, 1)
            d(a(i, 1)) = 1
            Next i
            For Each b In .keys
                With ws.Range(ws.Cells(5, 1), ws.Cells(ws.Cells(Rows.Count, 1).End(xlUp).Row, _
                    ws.Cells(1, Columns.Count).End(xlToLeft).Column))
                    .AutoFilter 10, b
                    .Offset(1).Resize(.Rows.Count - 1).Copy Worksheets(CStr(b)).Cells(Rows.Count, "A").End(xlUp).Offset(1)
                    .AutoFilter
                End With
            Next b
        End With
    End With
End Sub
 
Upvote 1
Solution
This is pretty much what @LazyBug suggested, with just a couple of minor tweaks. Please try it on a copy of your workbook:
VBA Code:
Option Explicit
Sub motilulla()
    Dim ws As Worksheet
    Set ws = Worksheets("Result 100 to 114")
    Dim d As Object, c As Range, i As Long, a, b
    Set d = CreateObject("scripting.dictionary")
    a = ws.Range("J6", ws.Cells(Rows.Count, "J").End(xlUp))
   
    With ws
        With d
            For i = 1 To UBound(a, 1)
            d(a(i, 1)) = 1
            Next i
            For Each b In .keys
                With ws.Range(ws.Cells(5, 1), ws.Cells(ws.Cells(Rows.Count, 1).End(xlUp).Row, _
                    ws.Cells(1, Columns.Count).End(xlToLeft).Column))
                    .AutoFilter 10, b
                    .Offset(1).Resize(.Rows.Count - 1).Copy Worksheets(CStr(b)).Cells(Rows.Count, "A").End(xlUp).Offset(1)
                    .AutoFilter
                End With
            Next b
        End With
    End With
End Sub
Hello @kevin9999, yes your tweaks are just perfect code worked like magic every copy goes into their corresponding sum sheet and paste it below header from row 6 to down. 🤝

Have a nice weekend and good luck.

Regards,
Moti :)
 
Upvote 0
Hello @kevin9999, yes your tweaks are just perfect code worked like magic every copy goes into their corresponding sum sheet and paste it below header from row 6 to down. 🤝

Have a nice weekend and good luck.

Regards,
Moti :)
Glad we were able to help Moti, and thanks for the feedback 👍 😀
 
Upvote 0

Forum statistics

Threads
1,215,403
Messages
6,124,710
Members
449,182
Latest member
mrlanc20

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