ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cell address in a given selection range. (https://www.excelbanter.com/excel-programming/365103-cell-address-given-selection-range.html)

dev

Cell address in a given selection range.
 
I have a method which returns Excel selection Range using get_Address()
method. I am tyring to return all the cells in that selection range.

Ex: If I have selection Range from $A$1:$B$2 (this is my input) then I want
to output
$A$1
$A$2
$B$1
$B$2

Is it possible to achieve this using Excel OM?


dev

Cell address in a given selection range. Help please!!
 
The below sub is returning correct cellAddress
==============================
Sub Macro1()
Dim cell As Range
Dim cellAddress As String
For Each cell In Range("B1:C3")
cellAddress = cell.Address(Null, Null, xlA1, Null, Null)
MsgBox (cellAddress)
Next
End Sub

But this is not working - Can't I loop thru the Range like
below?========================================
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cell As Range
Dim cellAddress As String
For Each cell In Range
cellAddress = cell.Address(Null, Null, xlA1, Null, Null)
MsgBox (cellAddress)
Next
End Sub


"Dev" wrote:

I have a method which returns Excel selection Range using get_Address()
method. I am tyring to return all the cells in that selection range.

Ex: If I have selection Range from $A$1:$B$2 (this is my input) then I want
to output
$A$1
$A$2
$B$1
$B$2

Is it possible to achieve this using Excel OM?



All times are GMT +1. The time now is 01:38 AM.

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