셀 범위에 값이 있는지 알아보고, 그렇지 않은 경우 함수를 실행하려고합니다.배열에 셀 값을 넣을 때 VBA 런타임 오류가 발생합니다.
- 내가 선
titles(i) = cell.Value
에 오류Run-time error 9 - Subscript out of range
을 얻고있어 - 내가 그러나이 문제가 엑셀 2007을 사용하고 있습니다.
- 배열에 값이 있는지 확인하기 위해
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 Yup :) Spot on –
첫 번째 부분이 해결되었습니다. 두 번째 부분에 대한 팁은 전혀 없습니까? –
@DavidGard : http://stackoverflow.com/questions/11109832/how-to-find-if-an-array-contains-a-string –