I'm trying to find out if a value exists in a range of cells and, if not, run a function. I am using Excel 2007.
I have two problems however -
- I'm am getting an error
Run-time error 9 - Subscript out of range
on the linetitles(i) = cell.Value
. - I'm unaware of a one liner that can be used in an
If
statement to check if a value exists in an array.
Here is my code so far. Any pointers on how to solve these problems, or tips on approaches that maybe better, would be grately apprciated. Thanks.
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