VB Code - Merge 5 sheets create Run-time error 1004

NeedHelp11

New Member
Joined
Jun 25, 2010
Messages
1
Dear VB-experts,

I have 5 worksheets that are updated regularly in a folder and then brought into a new summary workbook using vb code. This works all fine.

My problem is when I try to merge the 5 sheets to one summary sheet in the summary workbook using vb code.

Code:
Sub Step_5()
Dim ws As Worksheet
ActiveSheet.UsedRange.Offset(0).Clear
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name Then
ws.UsedRange.Offset(1).Copy
With Range("A65536").End(xlUp).Offset(1, 0)
.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End With
End If
Next
End Sub

When I run the code I get error message 1004 "application-defined or object-defined error".
The first four sheets are copied fine, but the last one is not copied at all.
The problem showed when debugging is marked in red.

I have searched for this in different threads. One solution could maybe be to copy one sheet, save, close the workbook then copy the second sheet, save, close the workbook etc? I am a beginner in VB and I really do not know how to solve this run-time error.

I would be very grateful for any solutions!



 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
welcome to the board

Its difficult to tell what is causing your problem from looking at this code

Initial thoughts, which may be well wide of the mark:
is that sheet protected?
how big is the usedrange / what region does it cover? How big is the combination of all usedranges on all sheets?

Do you know how to name your ranges, and use these names in your code? (insert>name>define in xl03, formulas>name manager in xl07)
example VBA
Code:
e.g. range("mynamedrange").copy

can this work for you?
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,435
Members
452,326
Latest member
johnshaji

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