ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Last column in selection (https://www.excelbanter.com/excel-programming/295515-last-column-selection.html)

Lawlera

Last column in selection
 
Can anyone please help me with some code to return the column number of the last cell in a selected range

TIA

incjourn

Last column in selection
 
This might not be the best way but it works

-----------------------------------

For Each B In Selection
C = B.Column
Next B

lastcol = C

-----------------------------------

Regard

--
Message posted from http://www.ExcelForum.com


Norman Jones

Last column in selection
 
Hi Lawlera,

Try

selection(selection.cells.count).column

---
Regards,
Norman.

"Lawlera" wrote in message
...
Can anyone please help me with some code to return the column number of

the last cell in a selected range?

TIA




Bob Phillips[_6_]

Last column in selection
 
With ActiveSheet.UsedRange
iCol = .Columns.Count + .Cells(1, 1).Column - 1
End With



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Lawlera" wrote in message
...
Can anyone please help me with some code to return the column number of

the last cell in a selected range?

TIA




Norman Jones

Last column in selection
 
Hi Bob,

I suspect that this (elegantly) returns the last column in the sheet rather
than the selection.

---
Regards,
Norman Jones

"Bob Phillips" wrote in message
...
With ActiveSheet.UsedRange
iCol = .Columns.Count + .Cells(1, 1).Column - 1
End With



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Lawlera" wrote in message
...
Can anyone please help me with some code to return the column number of

the last cell in a selected range?

TIA






Rob van Gelder[_4_]

Last column in selection
 
I have some examples in the Working with Ranges section of my website.

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Lawlera" wrote in message
...
Can anyone please help me with some code to return the column number of

the last cell in a selected range?

TIA




Lawlera

Last column in selection
 
Lots of answers .. all different

Got what I needed so thanks to everyone!

Bob Phillips[_6_]

Last column in selection
 
You are correct, for Selectiuon it should be

With Selection
iCol = .Columns.Count + .Cells(1, 1).Column - 1
End With

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Norman Jones" wrote in message
...
Hi Bob,

I suspect that this (elegantly) returns the last column in the sheet

rather
than the selection.

---
Regards,
Norman Jones

"Bob Phillips" wrote in message
...
With ActiveSheet.UsedRange
iCol = .Columns.Count + .Cells(1, 1).Column - 1
End With



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Lawlera" wrote in message
...
Can anyone please help me with some code to return the column number

of
the last cell in a selected range?

TIA









All times are GMT +1. The time now is 08:47 PM.

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