Hallo Christopher,
so sollte es gehen:
Option Explicit
Private Sub cmbOK_Click()
Dim rngVokabeln As Range
Dim strEnglisch As String
Dim wsVokabeln As Worksheet
Dim lngLetzteZeile As Long
Set wsVokabeln = ThisWorkbook.Sheets("Vokabeln")
With wsVokabeln
lngLetzteZeile = .Cells(Rows.Count, 1).End(xlUp).Row
Set rngVokabeln = .Range(.Cells(2, 2), .Cells(lngLetzteZeile, 3))
strEnglisch = Application.VLookup(lblDeutsch, rngVokabeln, 2, False)
End With
If (TextBox1.Value) = strEnglisch Then
MsgBox "Richtig"
Else
MsgBox "Falsch"
End If
Unload frmVokabelTest
End Sub
Private Sub UserForm_Initialize()
'Voreinstellungen bei Erfassung
Dim lngLetzteVokabel As Long
Dim lngZufallszahl As Long
Dim strDeutsch As String
Dim rngVokabeln As Range
With Sheets("Vokabeln")
lngLetzteVokabel = .Cells(Rows.Count, 1).End(xlUp).Row
lngZufallszahl = Application.WorksheetFunction.RandBetween(2, lngLetzteVokabel)
Set rngVokabeln = .Range(.Cells(2, 1), .Cells(lngLetzteVokabel, 3))
strDeutsch = Application.VLookup(.Cells(lngZufallszahl, 1), rngVokabeln, 2, False)
End With
With Me
.lblNummer = lngZufallszahl
.lblDeutsch = strDeutsch
End With
End Sub
Viele Grüße
Kai
|