Object Required VBA

jamesmev

Board Regular
Joined
Apr 9, 2015
Messages
233
Office Version
  1. 365
Platform
  1. Windows
I am attempting to merge multiple sheets together using this code:
Code:
Sub Combine()  Dim lst As Long 'combines order form into winshuttle ready combinedOE
     Application.ScreenUpdating = False


   Sheets(1).Copy Sheets(1)
  With Sheets(1).Name
     lst = .Range("I" & Rows.Count).End(xlUp).Row + 1
    .Range("A" & lst).PasteSpecial xlPasteColumnWidths
    .Range("A" & lst).PasteSpecial xlPasteValues


End With
   With Sheets(1).UsedRange
      .ColumnWidth = 22
      .RowHeight = 18
      Application.ScreenUpdating = True
      Application.DisplayAlerts = True
      
   End With
End Sub

However I am getting object required error.
I can write this to where it copies and pastes over the first blank cell in row A. However, I need it to paste over the first blank cell after A2 in column J. (Since A2 will always be blank)

please help.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
This:

Code:
With Sheets(1).Name

should be just:

Code:
With Sheets(1)
 
Upvote 0
This:

Code:
With Sheets(1).Name

should be just:

Code:
With Sheets(1)

I am now getting Run-Time Error '1004':
PasteSpecial Method of Range class failed.

here:
Code:
.Range(A") &lst).PasteSpecial xlPasteColumnWidths
 
Upvote 0
You just copied a worksheet, not a range, so you can't paste. What are you actually trying to do?
 
Upvote 0
I am now getting Run-Time Error '1004':
PasteSpecial Method of Range class failed.

here:
Code:
[COLOR=#333333].Range(A") &lst).PasteSpecial xlPasteColumnWidths[/COLOR]
Also, this would not be correct syntax anyway.
Code:
[COLOR=#333333].Range(A") &lst)[/COLOR]
should be:
Code:
[COLOR=#333333].Range("A" & lst)[/COLOR]
like you had in your original post.
 
Last edited:
Upvote 0
I am combining workbooks from a network source.
The worksheets starts on A2. when merging it is overwriting all the data of the other records if A is blank.

here is the format of what should be copied and pasted.

A B C D E F G H I J
1 DATA DATA DATA DATA DATA DATA DATA DATA
2 DATA DATA
3 DATA DATA
4 DATA DATA
5 DATA DATA
6 DATA DATA

The next copied sheet should provide the same format.
However, it is pasting over the Data in I & J because A2 is blank.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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