ranuse
02-21-2011, 09:58 PM
Hi,
I'm having trouble with the error described in the title, error 91. My code is trying to find a string in the first row of the worksheet and return the column number. I expect that if it does not find anything, the function returns 0. When I run the code on a blank worksheet, I receieved error 91. In the debug mode, temp is shown to equal 0....so I'm not sure what the problem is.
Any advices is appreciated.
Dim i As Integer
Dim temp As Integer
Dim RequiredFields As Variant
RequiredFields = Array("Failed", "Not Executed", "Passed")
For i = 0 To 2
temp = Rows(1).Find(RequiredFields(i)).Column
If temp = 0 Then
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Select
ActiveCell.FormulaR1C1 = RequiredFields(i)
End If
Next i
I'm having trouble with the error described in the title, error 91. My code is trying to find a string in the first row of the worksheet and return the column number. I expect that if it does not find anything, the function returns 0. When I run the code on a blank worksheet, I receieved error 91. In the debug mode, temp is shown to equal 0....so I'm not sure what the problem is.
Any advices is appreciated.
Dim i As Integer
Dim temp As Integer
Dim RequiredFields As Variant
RequiredFields = Array("Failed", "Not Executed", "Passed")
For i = 0 To 2
temp = Rows(1).Find(RequiredFields(i)).Column
If temp = 0 Then
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Select
ActiveCell.FormulaR1C1 = RequiredFields(i)
End If
Next i