背景
我的代码在范围内执行一些循环,但是,每个交互应该在不包括刚执行的单元格的范围内执行.我认为更简单的方法是从存储的范围中删除单元格.
问题
我无法找到从存储对象中删除单元格的方法
代码
问题是一般的但是,对于问题,它会像
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 …Run Code Online (Sandbox Code Playgroud) 背景:
我一直使用以下重置它们:
Sub TestWithRedimOnly()
Dim ExampleArray() As String
ReDim Preserve ExampleArray(1)
ExampleArray(1) = "yo"
MsgBox ExampleArray(1)
ReDim ExampleArray(0) As String
MsgBox ExampleArray(1) 'this confirms is reset!
End Sub
Run Code Online (Sandbox Code Playgroud)
如果我擦除
Sub TestWithEraseAndRedim()
Dim ExampleArray() As String
ReDim Preserve ExampleArray(1)
ExampleArray(1) = "yo"
MsgBox ExampleArray(1)
Erase ExampleArray
MsgBox ExampleArray(1) 'this confirms is reset!
ReDim ExampleArray(0) As String
MsgBox ExampleArray(1) 'this confirms is reset!
End Sub
Run Code Online (Sandbox Code Playgroud)
最后,都重置变量。
问题:
使用擦除语句真的值得吗?是否可以防止内存泄漏比仅仅防止内存泄漏更好Redim.. As..?
背景:
我使用标准化名称在userform中有一组对象(对于此示例Listbox对象),我想使用计数器循环动态重命名它们.

问题:
如果我要问的是甚至可能的话,我还没想办法,但是,我想确认一下.
解决方法:
到目前为止没有任何内容,就像我说的那样(参考上图)我需要一种方法来设置for循环中对象的值,如下所示:
For CounterItems = 1 To 18 'Hours in Template
ListBox_Time(CounterItems).Value="Dummy" & CounterItems
Next CounterHours
Run Code Online (Sandbox Code Playgroud)
但是,我对如何这样做(或者如果它是可以实现的)毫无头绪.
问题:
有没有办法使用计数器来转换变量/对象?