Try this:
Option Explicit
Sub Inspect()
Dim LValue As String, LValue2 As String
Dim lngLastRow As Long, i As Long
lngLastRow = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To lngLastRow
If InStr(Range("F" & i), "FORECLOSURE") Then
If InStr(Range("J" & i), "DEFENDANT") Then
If InStr(Range("G" & i), " V ESTATE OF ") <> 0 Then
Range("N" & i) = Trim(Mid(Range("G" & i), InStr(Range("G" & i), " V ESTATE OF ") + 12, 100))
ElseIf InStr(Range("G" & i), " V ") <> 0 Then
Range("N" & i) = Trim(Mid(Range("G" & i), InStr(Range("G" & i), " V ") + 3, 100))
ElseIf InStr(Range("G" & i), " VS ") <> 0 Then
Range("N" & i) = Trim(Mid(Range("G" & i), InStr(Range("G" & i), " VS ") + 4, 100))
End If
If InStr(Range("K" & i), " ") <> 0 Then
Range("O" & i) = Range("K" & i)
Else
If InStr(Range("K" & i), "UNKNOWN SPOUSE") > 0 Then
Range("O" & i) = Trim(Replace(Left(Range("K" & i), Len(Range("K" & i)) - 1), "_", ""))
Else
Range("O" & i) = Trim(Replace(Range("K" & i), "_", ""))
End If
End If
End If
End If
Next i
End Sub
The problem was you hadn't put in the UNKNOWN SPOUSE stuff anywhere, and you were only filling in your LValue variable when there were dblspaces. Since most of your variables were only being referenced one time, I took a bunch out and issued commands directly against the one-time calculations.
Also, based on your final instructions above, you had the wrong information going into N and O, backwards.
Bookmarks