I am trying to find a string in excel sheet and store the string cell address in an array. This string appears several times. By storing every cell address where the string is located, im checking if the string is located one below another (in row) or one beside another (in column). But I am having a type mismatch error 13, please someone help me. Code is as following:
Sorry for such a long code:
Some one let me know even if there is a better solution.
Thank you.
Sorry for such a long code:
Code:
Sub Find()
Dim find1, find2, find3, find4 As Range
Dim FirstFound As String
Dim i As Integer
Dim y(), z() As Long
i = 1
Application.FindFormat.Clear
Set find1 = Cells.Find(What:=Trim("Amplifier type"), _
After:=Cells(1, 1), _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)
If Not find1 Is Nothing Then
'if found, remember location
FirstFound = find1.Address
'y(i) = cl.Row
'z(i) = cl.Column
Do
find1.Font.Bold = True
find1.Interior.ColorIndex = 3
Set find1 = Cells.FindNext(After:=find1)
ReDim Preserve y(i)
ReDim Preserve z(i)
y(i) = find1.Row
z(i) = find1.Column
i = i + 1
Loop Until FirstFound = find1.Address
End If
For i = 1 To UBound(y)
If ((y(i) = y(i + 1)) & (z(i + 1) - z(i) = 1)) Then
MsgBox "Horizontal"
End If
If ((z(i) = z(i + 1)) & (y(i + 1) - y() = 1)) Then
MsgBox "Vertical"
Next i
End Sub
Some one let me know even if there is a better solution.
Thank you.
Comment