I have a range of cells (A1:C13) as shown in the picture.
I wrote code to search for cells within this range that contain the string "Node" and then grab the contents from the cell directly below the matched cell. The code reports the results in the format Node XX = XXX in column E of the same sheet.
My aim is to directly export the results of my loop into a text file as shown in the picture. I searched the forums for a solution.
Picture of my search range, my current results and my expected results:
Sub Find_Nodes_text()
Dim CompId As Range
Dim i As Byte
Dim FirstMatch As Variant
Dim TXT As String
Range("E:E").ClearContents
i = 1
Set CompId = Range("A1:C13").Find(what:="Node", LookIn:=xlValues, lookat:=xlPart)
If Not CompId Is Nothing Then
TXT = CompId.Value & " = " & CompId.Offset(1, 0).Value
Range("E" & i).Value = TXT
FirstMatch = CompId.Address
Do
Set CompId = Range("A1:C13").FindNext(CompId)
If CompId.Address = FirstMatch Then Exit Do
i = i + 1
TXT = CompId.Value & " = " & CompId.Offset(1, 0).Value
Range("E" & i).Value = TXT
Loop
Else
MsgBox "No Nodes Found!"
End If
End Sub