VBA won't copy third value of a range from multiple sheets

cpmurray1985

New Member
Joined
Mar 10, 2022
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have this macro code that can copy a range of cells from multiple worksheets into one worksheet(Archive) and display it in a list. However, if I have the range set from D2:T4, it will only get D2:T3, for maybe the first few sheets, then D2:T3 for the rest, skipping all of row 3 for some worksheets. It will also skip row 4, so I would have to mark it as D2:T5, to at least get row 4 up to T4. I have it post in column D, which fills to column T, but it skips row 3 at times (at first I thought it was because some cells in row 3 in the worksheets were empty, so I filled them in with text, but it still does it regardless as if it was never there) and will skip row 4 unless you put "D2:T5".

Thank you.

VBA Code:
Public Sub m()
    Dim lRow As Long
    Dim sh As Worksheet
    Dim shArc As Worksheet
    Set shArc = ThisWorkbook.Worksheets("Archive")
    For Each sh In ThisWorkbook.Worksheets
        Select Case sh.Name
            Case Is <> "Archive"
                lRow = shArc.Range("D" & Rows.Count).End(xlUp).Row
                sh.Range("D2:T5").Copy _
                    Destination:=shArc.Range("D" & lRow)
        End Select
    Next
    Set shArc = Nothing
    Set sh = Nothing
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Note that you are finding the last row on the "Archive" sheet, and then pasting over it.
I think you want to find the last row, then post to the row BELOW that.

You can do that by changing this line:
VBA Code:
                    Destination:=shArc.Range("D" & lRow)
to this:
VBA Code:
                    Destination:=shArc.Range("D" & lRow + 1)
 
Upvote 0
Solution
Note that you are finding the last row on the "Archive" sheet, and then pasting over it.
I think you want to find the last row, then post to the row BELOW that.

You can do that by changing this line:
VBA Code:
                    Destination:=shArc.Range("D" & lRow)
to this:
VBA Code:
                    Destination:=shArc.Range("D" & lRow + 1)
Thank you so much, that was exactly what I was looking for and it now works!
 
Upvote 0
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,215,101
Messages
6,123,094
Members
449,095
Latest member
gwguy

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