我试图找出一个值是否存在于一个单元格中,如果不存在,则运行一个函数。我正在使用Excel 2007。
不过,我有两个问题-
Run-time error 9 - Subscript out of range上得到了一个错误titles(i) = cell.Value。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发布于 2012-09-28 10:01:11
因为您试图在初始化数组之前分配一个值,所以您会得到该错误。
Dim titles() As String
i = 0
For Each cell In title_range
titles(i) = cell.Value
'
'
Nexthttps://stackoverflow.com/questions/12637665
复制相似问题