Finding a last column

Eurekaonide

Active Member
Joined
Feb 1, 2010
Messages
433
Dear All

I have a formula VBA code to find the last row but how do you find the last cell entered in the columns to the right.

the code I wouls use for the last row is;
LastRow = Range("A" & Rows.Count).End(xlUp).Row

I tried this but thst didnt work;
Lastcolumn = Range("2" & Columns.Count).End(xlLeft).Column
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Thank you,
I am then trying to copy a formula across all those cells in that row and have the following but now thats not recognised either :-(

So I have this, the second line is now what is not working.


lastcolumn = Cells(2, Columns.Count).End(xlToLeft).Column
Range("F3").AutoFill Destination:=Range("F3:3" & lastcolumn)

I think it must be the range that is wrong?
 
Upvote 0
Will this work?
Code:
Range("F3").AutoFill Destination:=Range(Cells(3, 6), Cells(3, lastcolumn))
 
Upvote 0
You're welcome..

Just FYI

Range uses column LETTERS
Range("A1")

Cells uses column NUMBER (or letter)
Cells(row#, column# OR letter)
Cells(1,1) same as Range("A1")
Cells(1,"A") same as Range("A1")

Hope that helps.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,335
Members
452,636
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