我试图找出一个单元格区域中是否存在值,如果不存在,请运行一个函数。我使用Excel 2007中将单元格值放入数组时将VBA运行时错误
我不过有两个问题 -
- 我点上线
titles(i) = cell.Value
收到错误Run-time error 9 - Subscript out of range
。 - 我不知道可以在
If
语句中使用的单线程来检查数组中是否存在值。
这是我的代码到目前为止。任何关于如何解决这些问题的指针,或者关于可能更好的方法的提示,都会非常感谢。谢谢。
Sub start()
Dim title_range As Range ' The range that contains the column titles
Dim cell As Range ' The individual cell from the title range
Dim titles() As String ' The column titles
Dim i As Integer ' Dummy for count
' Set the column titles range
Set title_range = ActiveWorkbook.Sheets("DJG Marketing - Client List by ").Range("A1:DZ1")
i = 0
For Each cell In title_range
titles(i) = cell.Value
i = i + 1
ReDim Preserve titles(i)
Next
If {value 'Matter open month' does not exist in the array `titles`} Then
create_month_column
End If
End Sub
+ 1是的:)现货 –
非常感谢,这是第一部分解决。第二部分的任何提示呢? –
@DavidGard:看到这个http://stackoverflow.com/questions/11109832/how-to-find-if-an-array-contains-a-string –