Background
My code does some loops over ranges, however, each interaction should be performed in the range excluding the cell just performed. I think the easier way to do so is to remove the cell from the stored range.
Problem
I have not been able to find a way to remove cell from the stored object
Code
The question is general but, for the matters it would be something like
Sub Sample()
Dim RangeToAnalyze As Range
Dim CounterRange As Long
Dim ExcludeCell As Range 'sample on what is desired to achieve
Set RangeToAnalyze = Selection 'this is based on some other criteria but, in order to reproduce it easier that's why selection
For CounterRange = 1 To 5
Set ExcludeCell = RangeToAnalyze.Find("text")
'now here I would like to find the next cell, but it should exclude the first one in order to go to the next one
Set RangeToAnalyze = RangeToAnalyze.Exclude(ExcludeCell) 'this is what I want to do, so when looping it could jump to the next find (This function is "sample" this is what I am looking to do
Next CounterRange
End Sub
To find the 5th
"text"
you can use.FindNext
Another alternative can be to replace the found
"text"
with something else temporarilyAlternative to the alternative is to store the 5
"text"
ranges into one Range withUnion
, clear the values of that range, and then set them back to"text"
when doneYou would be better to use a For... Each loop I suspect. This should be a starting place:
This should then perform your actions on each cell and move on to the next one and automatically stop at the last cell.
You can also nest this inside another For... Each loop to cycle different ranges as well and so on.
One approach could be this
Test the function