ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Last row - Selected Column (https://www.excelbanter.com/excel-programming/346367-last-row-selected-column.html)

Desert Piranha[_2_]

Last row - Selected Column
 

Hi all,
I know how to get the last row with the column "hard coded" IE:

Code:
--------------------
Sub Example1()
Cells(Cells.Rows.Count, "A").End(xlUp).Select
End Sub

--------------------
But instead of hard coding a column i want to select the column.
something like:
Code:
--------------------
Sub Example2()
Cells(Cells.Rows.Count, "With Selection").End(xlUp).Select
End Sub

--------------------
It dosen't work of course. Any direction on this would be appreciated.
Thx
Dave


--
Desert Piranha
------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=487496


Leith Ross[_310_]

Last row - Selected Column
 

Hello Desert Piranha,

Dim Col
Cells(Cells.Rows.Count, Col).End(xlUp).Select

Since Col is a variant it can then be a string like "A" or a number
like 1.

RETURN THE FIRST COLUMN OF A SELECTION:
FirstCol = Selection.Column

RETURN THE LAST COLUMN OF A SELECTION:
With Selection
LastCol = .Columns.Count + .Column - 1
End With

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=487496


Rowan Drummond[_3_]

Last row - Selected Column
 
Try:

Sub Example1()
Cells(Rows.Count, ActiveCell.Column).End(xlUp).Select
End Sub

Regards
Rowan

Desert Piranha wrote:
Hi all,
I know how to get the last row with the column "hard coded" IE:

Code:
--------------------
Sub Example1()
Cells(Cells.Rows.Count, "A").End(xlUp).Select
End Sub

--------------------
But instead of hard coding a column i want to select the column.
something like:
Code:
--------------------
Sub Example2()
Cells(Cells.Rows.Count, "With Selection").End(xlUp).Select
End Sub

--------------------
It dosen't work of course. Any direction on this would be appreciated.
Thx
Dave



Norman Jones

Last row - Selected Column
 
Hi Dave,

Try:
'===========
Public Sub Example2()
Cells(Cells.Rows.Count, _
ActiveCell.Column).End(xlUp).Select
End Sub
'<<===========

PS: Desert?!

---
Regards,
Norman



"Desert Piranha"
<Desert.Piranha.1yxlhz_1132718402.6354@excelforu m-nospam.com wrote in
message news:Desert.Piranha.1yxlhz_1132718402.6354@excelfo rum-nospam.com...

Hi all,
I know how to get the last row with the column "hard coded" IE:

Code:
--------------------
Sub Example1()
Cells(Cells.Rows.Count, "A").End(xlUp).Select
End Sub

--------------------
But instead of hard coding a column i want to select the column.
something like:
Code:
--------------------
Sub Example2()
Cells(Cells.Rows.Count, "With Selection").End(xlUp).Select
End Sub

--------------------
It dosen't work of course. Any direction on this would be appreciated.
Thx
Dave


--
Desert Piranha
------------------------------------------------------------------------
Desert Piranha's Profile:
http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=487496




Desert Piranha[_3_]

Last row - Selected Column
 

Hi all,
Leith, Rowan, Norman,
Thx for your fast and wonderfull input. It's all great, and solved my
issue.

Norman - Yes "Desert" I'm in the desert of Arizona, USA, - Scorpions,
Rattle Snakes,
Black Widows, Coyotes, Tarantulas, and Catcus.
My nickname is Piranha, hence Desert Piranha.
Norman Jones Wrote:
Hi Dave,

Try:
'===========
Public Sub Example2()
Cells(Cells.Rows.Count, _
ActiveCell.Column).End(xlUp).Select
End Sub
'<<===========

PS: Desert?!

---
Regards,
Norman



"Desert Piranha"
<Desert.Piranha.1yxlhz_1132718402.6354@excelforu m-nospam.com wrote in
message
news:Desert.Piranha.1yxlhz_1132718402.6354@excelfo rum-nospam.com...

Hi all,
I know how to get the last row with the column "hard coded" IE:

Code:
--------------------
Sub Example1()
Cells(Cells.Rows.Count, "A").End(xlUp).Select
End Sub

--------------------
But instead of hard coding a column i want to select the column.
something like:
Code:
--------------------
Sub Example2()
Cells(Cells.Rows.Count, "With Selection").End(xlUp).Select
End Sub

--------------------
It dosen't work of course. Any direction on this would be

appreciated.
Thx
Dave


--
Desert Piranha

------------------------------------------------------------------------
Desert Piranha's Profile:
http://www.excelforum.com/member.php...o&userid=28934
View this thread:

http://www.excelforum.com/showthread...hreadid=487496



--
Desert Piranha
------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=487496


Norman Jones

Last row - Selected Column
 
Hi Dave,

Norman - Yes "Desert" I'm in the desert of Arizona, USA, - Scorpions,
Rattle Snakes,
Black Widows, Coyotes, Tarantulas, and Catcus.
My nickname is Piranha, hence Desert Piranha.


Thank you for the information.

The Desert portion appeared to be a new appellation - hence the query.

---
Regards,
Norman



Desert Piranha[_4_]

Last row - Selected Column
 

Hi Norman,
Yes, just evolving along with the critters. :)
DaveNorman Jones Wrote:
Hi Dave,

Norman - Yes "Desert" I'm in the desert of Arizona, USA, -

Scorpions,
Rattle Snakes,
Black Widows, Coyotes, Tarantulas, and Catcus.
My nickname is Piranha, hence Desert Piranha.


Thank you for the information.

The Desert portion appeared to be a new appellation - hence the query.

---
Regards,
Norman



--
Desert Piranha
------------------------------------------------------------------------
Desert Piranha's Profile: http://www.excelforum.com/member.php...o&userid=28934
View this thread: http://www.excelforum.com/showthread...hreadid=487496



All times are GMT +1. The time now is 02:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com