I have the following code:
On Error GoTo no_match
found_discord = Application.WorksheetFunction.Match(char, table_rng.ListColumns("Chars").DataBodyRange, 0)
discord = table_rng.DataBodyRange(found_discord, 8).Value
If discord = "" Then
answer = MsgBox("This user has no discord on file. Do you know his discord?", vbYesNo)
If answer = "yes" Then
discord = InputBox("Please type user discord:")
If (Me.OptForever.Value = True And discord = "") Then
discord = "Banned Forever"
End If
Else
If Me.OptForever.Value = True Then
discord = "Banned Forever"
Else
discord = "No disc found"
End If
End If
End If
Set lrow = table_notes.ListRows.Add
With lrow
.Range(1) = char
.Range(2) = length
.Range(3) = Date
.Range(4) = end_time
.Range(6) = reason
.Range(7) = discord
End With
Check_discord discord, char, length, end_time, reason
sort_table4
lock_pass
Unload Me
Exit Sub
no_match:
MsgBox ("This Char is new to our database please insert data after clicking ok")
frmNewChar.Show
found_discord = Application.WorksheetFunction.Match(char, table_rng.ListColumns("Chars").DataBodyRange, 0)
discord = table_rng.DataBodyRange(found_discord, 8).Value
Resume Next
End Sub
The idea is for the code to use match function to lookup value. (this part works fine).
My issue is when the Match function doesn't find a match. Instead of running the code in the "no_match" area once and then continue with the rest of the code, VBA jumps to "no_match" after every line after the "if" statement.
Can anybody help me?
add following after the match function line
on error goto 0