I have the following code on the internet, to search for a string and return the row number. The enclosed code, does that. Being that I am not a programmer,
I would like to know, what I would need to do, if the value and the row number returned, does not meet a certain value, then insert rows.
example- I am searching for the string "Field Number". It returns a value of row No. 42, I need Field number to be in row 45, so I would need to insert 3 rows, above the found string value of "Field Number".
example~2, If found string value is in row 42, insert 3 rows.
If string value, and findrow=45, Do Nothing.
Sub xFind_String2() '(sFindText As String)
Dim i As Integer ' Integer used in 'For' loop
Dim iRowNumber As Integer ' Integer to store result in
iRowNumber = 0
' Loop through cells c1-c100 until 'sFindText' is found
For i = 1 To 100
If Cells(i, 3).Value = "Field Number" Then
' A match has been found to the supplied string
' Store the current row number and exit the 'For' Loop
iRowNumber = i
Exit For
End If
Next i
' Pop up a message box to let the user know if the text
' string has been found, and if so, which row it appears on
If iRowNumber = 0 Then
MsgBox "String " & sFindText & " not found"
Else
MsgBox "String " & sFindText & " found in cell C" & iRowNumber
End If
End Sub
Thank you in advance, for any suggestions in solving the code that would be needed.
I would like to know, what I would need to do, if the value and the row number returned, does not meet a certain value, then insert rows.
example- I am searching for the string "Field Number". It returns a value of row No. 42, I need Field number to be in row 45, so I would need to insert 3 rows, above the found string value of "Field Number".
example~2, If found string value is in row 42, insert 3 rows.
If string value, and findrow=45, Do Nothing.
Sub xFind_String2() '(sFindText As String)
Dim i As Integer ' Integer used in 'For' loop
Dim iRowNumber As Integer ' Integer to store result in
iRowNumber = 0
' Loop through cells c1-c100 until 'sFindText' is found
For i = 1 To 100
If Cells(i, 3).Value = "Field Number" Then
' A match has been found to the supplied string
' Store the current row number and exit the 'For' Loop
iRowNumber = i
Exit For
End If
Next i
' Pop up a message box to let the user know if the text
' string has been found, and if so, which row it appears on
If iRowNumber = 0 Then
MsgBox "String " & sFindText & " not found"
Else
MsgBox "String " & sFindText & " found in cell C" & iRowNumber
End If
End Sub
Thank you in advance, for any suggestions in solving the code that would be needed.