Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default returning multiple cell addresses

Hi All,

I have a situation where l need the user to select a multiple range of
cells in a single column by holding down the 'Ctrl' key and selecting
the cells. The cells are not likely to be contiginous.

Can anybody provide the code (or point me in the right direction) to
retrieve the cell addresses / rows once the selection has been made?

TIA

Regards

Michael Beckinsale

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default returning multiple cell addresses

Sub retriever()
Dim r As Range
Dim s As String
s = ""
For Each r In Selection
s = s & " " & r.Address
Next
MsgBox (s)
End Sub
--
Gary's Student


"michael.beckinsale" wrote:

Hi All,

I have a situation where l need the user to select a multiple range of
cells in a single column by holding down the 'Ctrl' key and selecting
the cells. The cells are not likely to be contiginous.

Can anybody provide the code (or point me in the right direction) to
retrieve the cell addresses / rows once the selection has been made?

TIA

Regards

Michael Beckinsale


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default returning multiple cell addresses

Hi
Selection.Address

will give you the address as a textstring.
NOTE:
If this string is long (more than 1024 characters, possibly less?) -
which occurs if there are lots of pieces in the selection, it can be
difficult to put this address back into a range object

e.g. Range(Selection.Address)

can give an error. In that case, you have to break the string up and
use Union to get the range back.
I have several functions for dealing with address strings if you need
them.
regards
Paul

michael.beckinsale wrote:
Hi All,

I have a situation where l need the user to select a multiple range of
cells in a single column by holding down the 'Ctrl' key and selecting
the cells. The cells are not likely to be contiginous.

Can anybody provide the code (or point me in the right direction) to
retrieve the cell addresses / rows once the selection has been made?

TIA

Regards

Michael Beckinsale


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default returning multiple cell addresses

Paul / Gary's Student.

Many thanks for your input.

Paul l understand what you are saying about the address text strings
but in this case it wont be a problem, but l would be interested in
your functions to help overcome the problem.

I eventually got my brain into gear and came up with the following code
which does what l want. The 'prev' variable is used to ensure that if
rows 1 or 65536 are selected they are not returned twice.

Sub RowsFromSelectedCells()

Dim prev As Long
Dim c As Range
prev = 0
For Each c In Selection
If c.Row < prev Then
MsgBox (c.Row) <<<<< enter required code here
End If
prev = c.Row
Next c

End Sub

Again thanks for your help,

Regards

Michael Beckinsale

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default returning multiple cell addresses

One way would be to loop through the Areas collection.

Dim A As Range
Dim S As String
If TypeOf Selection Is Excel.Range Then
For Each A In Selection.Areas
S = S & " " & A.Address
Next A
MsgBox S
End If

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)

"michael.beckinsale" wrote in message
oups.com...
Hi All,

I have a situation where l need the user to select a multiple range of
cells in a single column by holding down the 'Ctrl' key and selecting
the cells. The cells are not likely to be contiginous.

Can anybody provide the code (or point me in the right direction) to
retrieve the cell addresses / rows once the selection has been made?

TIA

Regards

Michael Beckinsale



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
returning multiple cell values from a vlookup SueB Excel Worksheet Functions 7 August 30th 08 12:28 AM
How to send specific cell ranges to multiple e-mail addresses Meghan Excel Programming 0 October 16th 06 06:14 PM
Sort multiple columns with multiple formulas without returning #R bellsjrb Excel Worksheet Functions 0 July 14th 06 10:01 AM
How to Import multiple-line addresses from Word into single cell? Queen Mother Excel Worksheet Functions 0 June 21st 06 06:06 PM
Returning Outlook email addresses GeorgeFD29 Excel Programming 2 December 23rd 05 03:25 AM


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

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"