LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Set few range variables at once

A couple of ideas involving collections, marked A & B

Sub test()
Dim i As Long
Dim rng As Range
Dim ColRanges As Collection 'A
Dim colNames As Collection 'B
Dim arrStates()

arrStates = Array("Alaska", "Alabama", "Arizona")

ReDim ar(1 To UBound(arrStates) + 1) As Range

i = 0
Set ColRanges = New Collection ' A
Set colNames = New Collection ' B

For Each zone In arrStates
i = i + 1
ColRanges.Add Cells(i, 1), zone 'A

Set ar(i) = Cells(i, 2) 'B
colNames.Add i, zone 'B
Next

i = 0
For Each r In ColRanges 'A
i = i + 1
Debug.Print r.Address
Next

Debug.Print "Arizona", ColRanges("Arizona").Address 'A

Debug.Print ar(colNames("Arizona")).Address 'B

End Sub

For your Set to found cells (subject error handing)

method A
ColRanges.Add foundRange, "myState"

method B
first populate the colNames collection
Set ar(colNames("myState")) = foundRange

Regards,
Peter T

"Greg" wrote in message
...
Hi,

Is there a way to do the below implicitly in a loop or as array? Thank

you!


Dim States As Range
Dim Alaska As Range, Alabama As Range, Arizona As Range 'etc

Set States = Range("a2:a51")

With States
Set Alaska = .Cells.Find("Alaska", lookat:=xlWhole, MatchCase:=False)
Set Alabama = .Cells.Find("Alabama", lookat:=xlWhole,

MatchCase:=False)
'...
'..
'etc

End With

--
______
Regards,
Greg





 
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
Adding a range with three variables Saul Excel Discussion (Misc queries) 4 July 25th 08 02:21 PM
Range of variables Ed Excel Programming 2 August 5th 06 03:05 PM
Describing a Range with Variables mazo Excel Programming 2 May 9th 06 02:28 PM
Naming Range Variables scott Excel Programming 6 January 7th 05 10:37 PM
Range Variables Daniel[_7_] Excel Programming 1 November 20th 03 05:45 AM


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

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"