VBA Problem (easy for you)

Jay Baker

New Member
Joined
Dec 9, 2003
Messages
15
I'm trying to select the first empty cell in a column (say column A) so I can paste some data.....the funny thing is, in my long subroutine the following code works, at times :unsure:

But at other places, I keep getting Run-time error 1004 Application defined or Object defined error.

code:
Worksheets("INPUT").Select
Range("A2").Select
Selection.Copy
Worksheets("SALES").Select
Range("A1").End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste

Thanks,
Frustrated,
:oops: :oops: :oops: Jay
 
Jay Baker said:
I then entered the following:

Sub Macro1()
Sheets("Sheet1").Select
Range("A2").Select
Selection.Copy
Sheets("Sheet2").Select
Range("A1").End(xlDown).Offset(1, 0).Select
ActiveSheet.Paste
Application.CutCopyMode = False
End Sub

Guess what....my good friend Runtime error 1004 reared his ugly head again!
This is my final attempt on this thread.

You will get a 1004 error if there is nothing in column A of the Sales sheet to begin with if you use that code of yours.

You will not get an error if you use what I posted for Test2, unless the Sales sheet is protected or cells are merged or some other who-knows-what-else thing is going on.
 
Upvote 0

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
OhMyGOD Chitosunday, :pray: :pray: :pray:

IT WORKS (y)

I used what you provided and put it several places in what I have written.
My little subroutine is getting so long I feel like a real "programmer" :LOL:

Thanks again,
Jay
 
Upvote 0
Hi Jay,
Looks like Chitosunday has your problem solved. Just a couple of points to think about. (1) If you avoid selecting in your code (similar to what I supplied) it will run much faster. (2) Fletch brings up a good point with starting at the bottom of Col A and working your way up instead of starting at the top & working down. (As long as there are no used cells in a range below whatever you're doing). This method will prevent the error if Col A is empty. (3) Tom provided a couple routines that work quite well that also check for error producing conditions and prevent them. You should (if you can) take the time to understand how these work. They will help you in the future. I find that when Tom (and Chitosunday for that matter!) "speak" it's usually beneficial to "listen".

Glad you got it working
(y)
Dan
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,895
Members
449,097
Latest member
dbomb1414

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