Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

collecting cell ID's

Status
Not open for further replies.

Luis939

MIS
Feb 28, 2003
453
US
how would i be able to collect cell id's where i spot discrepencies. i use this

Let i = ActiveCell.Address

and then later this, when i need to go back to that cell

Range(i).Select

but i can do this only for one cell, what if i have multiple cells whose address i need to collect, how would i do it so that everytime i encounter such an a cell i record its address and then later i go to the first cell, do someting to it, then the 2nd cell do the same thing, and etc until im done with the last cell, thanks!!
 
Wow, lots of possibilities on this. I might consider using a Collection, others might think an array of String, or perhaps an array of Range.

Let me think about this, I will get back later.
 
Here are code snippets:
Code:
Option Explicit
Dim OfTheRange, RangeCollection As New Collection

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
RangeCollection.Add Target.Address(False, False)
End Sub


Sub EnumerateCollectedRanges()
Debug.Print RangeCollection.Count
For Each OfTheRange In RangeCollection
    Debug.Print OfTheRange
Next
End Sub

Sub WhenYouAreDone()
Set RangeCollection = Nothing
End Sub
 
This is somewhat useless, but it demonstrates techniques

Code:
Sub ReplayTheSelections()
Dim loopcount As Integer

Select Case RangeCollection.Count

Case Is > 0
    Application.EnableEvents = False
    For Each OfTheRange In RangeCollection
        Range(OfTheRange).Select
        Application.Wait Now + TimeValue("00:00:01")
        loopcount = loopcount + 1
        Debug.Print loopcount
    Next
    
    Application.EnableEvents = True
    
    If MsgBox("You want to set the collection to Nothing?", vbYesNo, "What Next?") = vbYes Then
    Set RangeCollection = Nothing
    End If
Case 0
    MsgBox "No items in the collection"
End Select

End Sub
 
Hmm, really quickly can you explain what the difference is between array of string and array of range, does the former mean that its an array of the characters of a particular string, or something related, and does the latter mean an array of say different cells and things like that, thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top