![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 1,805
|
Hi all,
In my macro's I often use: set myRange = ActiveCell.CurrentRegion which allows refering to changing ranges. Now, I need to know the ADDRESS of some cells in that range and put into variable: say the first cell in the last column, or the third from top, second to the right. I need adress not content (e.g. "H1"). What is the VBA code for that? Many thanks, Eli [ This Message was edited by: eliW on 2002-04-26 02:18 ] |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Kobe, Japan
Posts: 1,420
|
Hi. Here is sample.
[ This Message was edited by: Colo on 2002-04-26 02:32 ] |
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Auckland, New Zealand
Posts: 4,209
|
Quote:
Have a look @ this code and take not of the comments; To test it make sure you have a valid range area and select within this range hen run it. Sub Range_Address() Dim MyRange As Range Dim oRow As Double, oCol As Double Dim x, y Set MyRange = Selection.CurrentRegion '// The oRow/oCol settings are important '// because the item method used on a range '// of cells will return results Even if they '// are outside of the range and you would '// only want a valid item address within the range you specify. oRow = MyRange.Rows.Count oCol = MyRange.Columns.Count MsgBox "Range address:=" & MyRange.Address For x = 1 To oRow For y = 1 To oCol MsgBox "Valid Addresses in " & MyRange.Address & ":=" & _ MyRange.Item(x, y).Address Next Next MsgBox "InValid Addresses in " & MyRange.Address & ":=" & _ MyRange.Item(10, 10).Address End Sub |
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Mar 2002
Posts: 1,805
|
Colo and Ivan
Thank you for your answers Eli |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|