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!



 

baitmaster

Well-known Member
Joined
Mar 12, 2009
Messages
2,031
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?
 

Forum statistics

Threads
1,082,384
Messages
5,365,144
Members
400,825
Latest member
Sreekanth_21

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top