I have been looking online for a solution but I keep getting an error no matter what I try.
I have about 20 worksheets and I want to copy the same range for each worksheet and merge them to another worksheet to create a report.
I was able to modify this solution below but it's still not working and I don't know why.
Any help is appreciatd.
Sub forReport()
Dim lRow As Long
Dim copyRange As Range
Dim sh As Worksheet
Dim shReport As Worksheet
Set shReport = ThisWorkbook.Worksheets("ALLProjectForReport")
For Each sh In ThisWorkbook.Worksheets
Select Case sh.Name
Case Is <> "ALLProjectForReport"
lRow = shReport.Cells(Rows.count, "A").End(xlUp).Row + 1
Set copyRange = sh.Range("A:B,D:D,F:F,J:K,L:L,BK:BK,GA:GB,GF:GF")
copyRange.Copy Destination:=shReport.Range("A" & lRow)
End Select
Next
Set shReport = Nothing
Set sh = Nothing
End Sub
But every time I get an error run-time '1004' highlighting this line
copyRange.Copy Destination:=shReport.Range("A" & lRow)
Any help?
试试这个快速修复:
Set copyRange = Intersect(sh.UsedRange, sh.Range("A:B,D:D,F:F,J:K,L:L,BK:BK,GA:GB,GF:GF"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.