背景
我的代码不超过范围有些循环中除去细胞,但是,每个相互作用应在的范围内不包括刚刚执行的细胞上进行。我认为更简单的方法是从存储的范围中删除单元格。
问题
我一直没能找到一种方法,从存储对象中删除单元格
代码
的问题是一般,但是,对于问题它会像从范围(对象)
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
时据我所知,没有本地的方式来做这个功能。尽管你有几个选择。你可以创建一个UDF,它将从一个范围中删除一个单元格,你可以改变你如何定义你的范围,或者你可以像平常一样循环范围,并检查“文本”,如果单元格包含文本那么不要在该单元上运行代码,循环跳到下一个。我个人推荐最后一个选项,它将需要对当前代码进行最少量的调整,并且仍然可以快速运行。 – tigeravatar
我想UDF是一种方法,你只是给了我一个关于如何去做的想法。太糟糕了,没有办法以本地方式来做到这一点。 – Sgdva
你不会喜欢这个答案,但是你将不得不做一堆'Intersect'或'Union'。你想找到第五个“文本”吗? – Slai