This macro to combine sheets omits some data, is it because of usedrange?

sheetspread

Well-known Member
Joined
Sep 19, 2005
Messages
5,160

Excel 2003
ABCDEF
1NameNumberNextnumber
2L995942
3M96432
4N267356
5O849463
6P930899
7Q626918
8R605845
9S60887
10T485605
11U287167
12V590374
13W998885
14X835116
15Y589958
16Z396236
17
188683
19Extra4343
First
Cell Formulas
RangeFormula
C18=SUM(C2:C17)




Excel 2003
ABCDEFGHI
1NameNumberNextnumber
2A290936
3B612997
4H510937Post455
5I935928
6J908312
7K395596
8L995942
9M96432
10N267356
11O849463
12P930899
13Q626918
14R605845
15S60887
16T485605
17U287167
18V590374
19W998885
20
2112079
Second
Cell Formulas
RangeFormula
C21=SUM(C2:C20)




Excel 2003
ABCDEFGHIJKL
1NameNumberNextnumber
2A290936
3B612997
4C49657
5D743652
6E658526
7F720117
8G521272
9R605845
10S60887
11T485605
12U287167
13V590374
14W998885
15X835116
16Y589958
17Z396236
18
199230
20
21
22
23
24Dont change766
25
26
27
28
29
30344
Third
Cell Formulas
RangeFormula
C19=SUM(C2:C18)



Code:
Sub allsheetstoone()
Dim i As Integer
Worksheets.Add.Name = "Master"
For i = 1 To Sheets.Count
If Sheets(i).Name <> "Master" Then
Sheets(i).UsedRange.Copy Destination:=Sheets("Master").Range("A" & Sheets("Master").UsedRange.Rows.Count)
End If
Next
End Sub


Excel 2003
ABCDEFGHIJKL
1NameNumberNextnumber
2L995942
3M96432
4N267356
5O849463
6P930899
7Q626918
8R605845
9S60887
10T485605
11U287167
12V590374
13W998885
14X835116
15Y589958
16Z396236
17
188683
19NameNumberNextnumber
20A290936
21B612997
22H510937Post455
23I935928
24J908312
25K395596
26L995942
27M96432
28N267356
29O849463
30P930899
31Q626918
32R605845
33S60887
34T485605
35U287167
36V590374
37W998885
38
39NameNumberNextnumber
40A290936
41B612997
42C49657
43D743652
44E658526
45F720117
46G521272
47R605845
48S60887
49T485605
50U287167
51V590374
52W998885
53X835116
54Y589958
55Z396236
56
579230
58
59
60
61
62Dont change766
63
64
65
66
67
68344
Master
Cell Formulas
RangeFormula
C18=SUM(C2:C17)
C57=SUM(C40:C56)


As you can see Row 19 from the First tab is missing/pasted over. I'm using usedrange.rows.count as the destination but rows.count+1 and rows.count.offset(1,0) (along with many other variations) haven't worked either.

So how can I vertically paste each sheet into one without omissions?


After someone solves this I'll work on preventing the extra headers and always putting the Master sheet first.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Assuming no filters in place try

Code:
Sub allsheetstoone()
Dim i As Integer
Worksheets.Add.Name = "Master"
For i = 1 To Sheets.Count
If Sheets(i).Name <> "Master" Then
    Sheets(i).UsedRange.Copy Destination:=Sheets("Master").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next
End Sub
 
Upvote 0
Thanks but that chops off another row:



Excel 2003
ABCDEFGHIJKL
1
2NameNumberNextnumber
3L995942
4M96432
5N267356
6O849463
7P930899
8Q626918
9R605845
10S60887
11T485605
12U287167
13V590374
14W998885
15X835116
16Y589958
17Z396236
18NameNumberNextnumber
19A290936
20B612997
21H510937Post455
22I935928
23J908312
24K395596
25L995942
26M96432
27N267356
28O849463
29P930899
30Q626918
31R605845
32S60887
33T485605
34U287167
35V590374
36W998885
37NameNumberNextnumber
38A290936
39B612997
40C49657
41D743652
42E658526
43F720117
44G521272
45R605845
46S60887
47T485605
48U287167
49V590374
50W998885
51X835116
52Y589958
53Z396236
54
559230
56
57
58
59
60Dont change766
61
62
63
64
65
66344
Master
Cell Formulas
RangeFormula
C55=SUM(C38:C54)
 
Upvote 0
Try

Code:
Sub allsheetstoone()
Dim i As Integer
Worksheets.Add.Name = "Master"
For i = 1 To Sheets.Count
If Sheets(i).Name <> "Master" Then
    Sheets(i).UsedRange.Copy Destination:=Sheets("Master").Range("C" & Rows.Count).End(xlUp).Offset(1, -2)
End If
Next
End Sub
 
Upvote 0
Not yet:


Excel 2003
ABCDEFGHIJKL
1
2NameNumberNextnumber
3L995942
4M96432
5N267356
6O849463
7P930899
8Q626918
9R605845
10S60887
11T485605
12U287167
13V590374
14W998885
15X835116
16Y589958
17Z396236
18
198683
20NameNumberNextnumber
21A290936
22B612997
23H510937Post455
24I935928
25J908312
26K395596
27L995942
28M96432
29N267356
30O849463
31P930899
32Q626918
33R605845
34S60887
35T485605
36U287167
37V590374
38W998885
39
4012079
41NameNumberNextnumber
42A290936
43B612997
44C49657
45D743652
46E658526
47F720117
48G521272
49R605845
50S60887
51T485605
52U287167
53V590374
54W998885
55X835116
56Y589958
57Z396236
58
599230
60
61
62
63
64Dont change766
65
66
67
68
69
70344
Master
Cell Formulas
RangeFormula
C19=SUM(C3:C18)
C40=SUM(C21:C39)
C59=SUM(C42:C58)



This is the first code I've written that requires the last nonblank row rather than cell, combining LR and LC, and of course it's a lot harder than I hoped.
 
Upvote 0
In Sheet "First" it's F which isn't printing but in Sheet "Second" it's I which is and "Third"'s L is also.
 
Upvote 0
Try

Code:
Sub allsheetstoone()
Dim i As Integer
Worksheets.Add.Name = "Master"
For i = 1 To Sheets.Count
If Sheets(i).Name <> "Master" Then
    LR = Sheets("Master").Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
    Sheets(i).UsedRange.Copy Destination:=Sheets("Master").Range("A" & LR + 1)
End If
Next
End Sub
 
Upvote 0
"Run Time Error 91: Object variable or with block variable not set"

LR = Sheets("Master").Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
 
Upvote 0
I will write out 100 lines "VoG is a pillock"

Code:
Sub allsheetstoone()
Dim i As Long, LR As Long
Worksheets.Add.Name = "Master"
For i = 1 To Sheets.Count
    If Sheets(i).Name <> "Master" Then
        With Sheets("Master")
            LR = 1
            On Error Resume Next
            LR = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
            On Error GoTo 0
            Sheets(i).UsedRange.Copy Destination:=.Range("A" & LR + 1)
        End With
    End If
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,676
Members
449,463
Latest member
Jojomen56

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