NessPJ
Active Member
- Joined
- May 10, 2011
- Messages
- 420
- Office Version
- 365
Hello all,
I wrote the following piece of VBA to find the right "Searchvalue" and only continue if the Searchvalue was indeed found.
The routine seems to go through every value it finds with this method and if the first one it finds isn't correct, the IF statement will go to the Else condition right away.
Something is wrong in my logic here?
I wrote the following piece of VBA to find the right "Searchvalue" and only continue if the Searchvalue was indeed found.
The routine seems to go through every value it finds with this method and if the first one it finds isn't correct, the IF statement will go to the Else condition right away.
Something is wrong in my logic here?
VBA Code:
Dim TabelnrBereikLR As Long
Dim Searchvalue As Long, Foundvalue As Long
'....start of my code....
TabelnrBereikLR = Sheets("Masterdata").Range("E65534").End(xlUp).Row
'Loop each cell in range
For n = TabelnrBereikLR To 4 Step -1
If RecenteInvoer = True Then
Searchvalue = RecentTabelnr
Else
Searchvalue = Tabelnr
End If
'Debug.Print "Searchvalue = "; Searchvalue
Foundvalue = Sheets("Masterdata").Range("B" & n).Value
If Format(Foundvalue, "00000") = Format(Searchvalue, "00000") Then
'Debug.Print "Found = "; Sheets("Masterdata").Range("B" & n).Value
GoTo TabelnrGevalideerd
Else
MsgBox "Het gekozen Tabelnummer / Printopdrachtnummer is nog niet gevuld of is niet geldig. De handeling kan niet worden uitgevoerd.", vbCritical, "Bewerking afgebroken"
GoTo EindeCancel
End If
Next
n = 0
TabelnrGevalideerd:
'...code to execute when the value was found...
Einde: '// Einde van de routine
Sheets("Menu").Activate
PROTON (Password)
Application.ActivePrinter = StandaardPrinter
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Exit Sub
EindeCancel:
Sheets("Menu").Activate
PROTON (Password)
Application.ActivePrinter = StandaardPrinter
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Exit Sub
End Sub