LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Finding last constant in range

I run Excel 2003.
I need to find the last constant in a range.
I have constructed a model of my data.
I start at A1 and the constants are in column 2.

My model's data is:
P Not0
O
N
M
L
K Not1
J
I
H
G Not2
F
E
D Not3
C
B Desired
A
Start

I have simple code to traverse the data.
Sub Macro1()
Dim List As Range
Dim Member As Range

' Excel renders lastcell - firstcell as firstcell - lastcell
Set List = Range(Cells(16, 2), Cells(1, 2))
' Grab constants in range
Set List = List.SpecialCells(xlCellTypeConstants)
For Each Member In List
Debug.Print Member.Address & " = " & Member.Value
Next Member
'
End Sub

That outputs
$B$1 = Not0
$B$6 = Not1
$B$10 = Not2
$B$13 = Not3
$B$15 = Desired

List consists of 5 members and I can easily get the desired datum
?list.Areas(list.Areas.Count)
Desired

If I add a datum to the end of my data
D Not3
C Not4
B Desired
A
Start

The range of 6 constants consists of 4 areas rather than 6.
I am looking for a 'simple' expression to find "Desired" - the last cell
in the range - in such a case.

I think my data always has the number of areas equal to the number of
constants, but would prefer not to rely on that assumption.

I went googling and this seems to work in both cases.
' Grab last constant
Set Member = List.Areas(List.Areas.Count)
Set Member = Member.Cells(Member.Cells.Count)
Debug.Print Member.Address & " = " & Member.Value

I now have a complete solution to my original problem.

What should I read to understand the structure of the range object?
--
Walter Briscoe
 
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
Public Range Constant - how do I? slarbie Excel Programming 13 December 13th 09 01:26 AM
Assigning a constant to a range name Al Excel Programming 8 February 28th 08 12:39 PM
range * constant linty Excel Programming 2 November 29th 04 02:41 PM
Multiply a Range by a Constant Jim Thomlinson[_3_] Excel Programming 0 November 22nd 04 08:23 PM
Selecting a constant changing Range Michael[_10_] Excel Programming 2 August 14th 03 01:30 PM


All times are GMT +1. The time now is 08:16 AM.

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

About Us

"It's about Microsoft Excel"