Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default 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



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Last column in selection

Lots of answers .. all different

Got what I needed so thanks to everyone!
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro help - add column selection HeatherJ Excel Worksheet Functions 1 June 4th 10 02:35 PM
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM
Automate column selection Snoopy Setting up and Configuration of Excel 1 January 27th 06 03:26 PM
Macro column selection Vispy Excel Programming 4 November 29th 03 08:56 PM
Total by Selection by Column, Help Please. Bubu Excel Programming 2 November 5th 03 03:57 PM


All times are GMT +1. The time now is 06:57 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"