Ich bastle wider mal endlos an einem Problem rum... und vermag es nicht selbst zu lösen.
Ich habe alle Funktionen die ich in einer Userform benötige in einem Klassenmodul untergebracht.
Dafür steht im code meiner userform ganz am Anfang:
Option Explicit
Dim oFunctionActiv As clsFunctionGenerell
...
und etliche Klassenmodule mehr.
Nun möchte ich in folgender Sub eine dieser Funktionen aufrufen.
Private Sub CommandButton25_Click()
Dim strEingabewertMineral As String 'Eingabewert Modul Nummer zu Text
Dim strEingabewertArtnr2 As String 'Eingabewert modul text zu nummer
Dim strEingabewertArtnr3 As String
Dim ArtnrTeil2 As String ' Nr Ergebniss Teil 2
Dim Mineral As String 'Text Mineral Ergebniss
Dim strArtnrTeil3 As String 'Nr Ergebniss Teil 2
Dim Blattname As String
Dim A As Variant 'Zähler allg.
Dim sp As Variant
Dim NZei As Integer
Dim VarSp2AktuellWert As String
Dim VarSp3AktuellWert As String
Dim strGanzeArtnr As String
Start:
TextBox8.SetFocus
NZei = 2
'Ist Mineral Leer
If ComboBox31.Value = "" Then
If TextBox4.Value = "" Then
MsgBox "Bitte Wählen Sie ein Mineral.", vbInformation, "Kein Mineral gewählt."
Exit Sub
Else
strEingabewertArtnr2 = TextBox4.Value
Mineral = oFunctionActiv.VergleichArtNr(strEingabewertArtnr2)
GoTo Teil2
End If
Else
strEingabewertMineral = ComboBox31.Value 'Für MineralSuchstring
strEingabewertArtnr2 = oFunctionActiv.VergleichMineral(strEingabewertMineral)
GoTo Teil2
End If
Teil2:
ArtnrTeil2 = oFunctionActiv.FormatierenArtikelnummer2(strEingabewertArtnr2)
A = 2
NZei = 2
sp = 59
Blattname = "Tabelle2"
Do While Tabelle2.Cells(NZei, 2).Value Empty
VarSp2AktuellWert = Trim(CStr(Tabelle2.Cells(NZei, 2).Text))
If VarSp2AktuellWert = ArtnrTeil2 Then
Tabelle2.Cells(A, sp).Value = Tabelle2.Cells(NZei, 3).Value
A = A + 1
End If
NZei = NZei + 1
Loop
If A = 2 Then
strEingabewertArtnr3 = 1
Else
' hier (fett,Kursiv Kriege ich einen laufzeitfehler 9 Index ausserhalb des gültigen bereiches!!! _
_
strEingabewertArtnr3 = oFunctionActiv.KleinsteLuecke(A, sp, Blattname)
End If
strArtnrTeil3 = oFunctionActiv.FormatierenArtikelnummer3(strEingabewertArtnr3)
strGanzeArtnr = ("01-" & strEingabewertArtnr2 & strArtnrTeil3)
Range(Tabelle2.Cells(2, sp), Tabelle2.Cells(A, sp)).ClearContents
TextBox4.Text = ArtnrTeil2
TextBox4.Locked = True
TextBox5.Text = strArtnrTeil3
TextBox5.Locked = True
CommandButton4.Visible = True
CommandButton9.Visible = True
CommandButton25.Visible = False
Label223.Visible = True
Label223.ForeColor = vbRed
ComboBox31.Locked = True
End Sub
Code der Funktion die aufgerufen werden soll:Public Function KleinsteLuecke(ByVal A, sp As Variant, ByVal Blattname As String)
Dim n, x As Long
Dim v()
Dim found As Boolean
v = Range(Sheets(Blattname).Cells(2, sp), Sheets(Blattname).Cells(A, sp)).Value
For x = 1 To 9999
found = False
For n = 1 To UBound(v)
If v(n, 1) = x Then
found = True
End If
Next n
If Not found Then
KleinsteLuecke = x
Exit Function
End If
Next x
End Function
Was läuft hier schief?
E liebs Griessli
Chatzebuseli