Posting into next empty column

JeremyGraham95

New Member
Joined
Jan 12, 2016
Messages
19
I AM STRUGGLING WITH GETTING THIS PIECE OF CODE TO WORK. i KEEP GETTING "APPLICATION DEFINED ERROR AND OBJECT DEFINED ERROR" AND CANT SEEM TO FIGURE OUT WHY. IT ALL LOOKS CORRECT TO ME. PLEASE HELP ME OUT





Dim source As Worksheet
Dim destination As Worksheet
Dim emptyColumn As Long


Set source = Sheets("Order Summary")
Set destination = Sheets("TRENDS")


'find empty Column (actually cell in Row 1)'
emptyColumn = destination.Cells(1, destination.Columns.Count).End(xlUp).Column
If emptyColumn > 1 Then
emptyColumn = emptyColumn + 1
End If


source.Range("B2:B127").Copy destination.Cells(1, emptyColumn)
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Welcome to the Board!

I'd think it's because you're using End(xlUp) instead of End(xlToLeft).

P.S. your Caps Lock is stuck. ;)
 
Upvote 0
You can do couple of things...

Code:
dim lcol as long
lcol=Cells.Find(What:="*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column+1

This will give you last Column+1 without any specific row..as in last filled column of your datasheet

Now if you want to find last fill column of row1 only then you can use this...

Code:
Dim lcol As Long
lcol = Cells(1, Cells.Columns.Count).End(xlToLeft).Column+1

This will give you basis of 1 Row only..

Saurabh...
 
Upvote 0
Thank you for the easy fix. could you tell me how i could modify the last line of the code so that the destination is d3? would i just copy the source part directly before it???
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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