Last column in selection

L

Lawlera

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

TIA
 
I

incjourn

This might not be the best way but it works

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

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

lastcol = C
 
N

Norman Jones

Hi Lawlera,

Try

selection(selection.cells.count).column

---
Regards,
Norman.

Lawlera said:
Can anyone please help me with some code to return the column number of
the last cell in a selected range?
 
B

Bob Phillips

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 said:
Can anyone please help me with some code to return the column number of
the last cell in a selected range?
 
N

Norman Jones

Hi Bob,

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

Bob Phillips

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)
 
Top