Guten Morgen,
ich benötige Hilfe bei einer Userform.
Wenn irgendmöglich möchte ich dazu keine Beispieldatei hochladen, da die datei sehr umfangreich ist, und wenn ich diese kürze bzw anonymisiere kaum noch was vernünftig läuft^^
Ich hoffe man kann mir über die Codes selber helfen.
Nun mein Anliegen:
Ich habe in einer UF eine Listbox diese reagiert aber leider nur auf Zahlen, bislang war das auch ausreichend. Aber ich möchte das jetzt etwas umarbeiten. Dafür wäre es aber von Vorteil wenn die Listbox auch auf text reagieren würde.
Momenten kommt es zum fehler wenn Text vorhanden ist.
Code:
Sub test()
Dim anz As Integer
Dim a As Integer
Dim b As Integer
Set ws = Worksheets("Lieferungen")
ls = ws.Cells(3, ws.Columns.Count).End(xlToLeft).Column
lz = ws.Cells(ws.Rows.Count, 3).End(xlUp).row
anz = Application.Count(ws.Range(ws.Cells(3, 5), ws.Cells(3, ls)))
ReDim arrBas(1 To lz, 1 To ls - 2)
ReDim arrDat(1 To lz)
ReDim arrArt(1 To anz)
arrBas = ws.Range(ws.Cells(3, 3), ws.Cells(lz, ls))
arrDat = ws.Range(ws.Cells(5, 3), ws.Cells(lz, 3))
For a = 5 To ls
If ws.Cells(3, a).Value <> "" Then
arrArt(b + 1) = ws.Cells(3, a).Value
b = b + 1
End If
Next a
For a = 1 To lz
If arrDat(a, 1) = Date Then
indDat = a
Exit For
End If
Next a
End Sub
Guten Morgen,
ich kann in deinem Code weder Anzeichen für eine UserForm noch füt eine ListBox finden....
Ausserdem, warum deklarierst Du manche Variabeln und manche nicht? Verwende Option Explicit! Wann wird dein Code von wem/was ausgelöst?
Gibt es Globale Variabeln? Was steht in deiner Tabelle?
Hallo, der Code ist nicht von mir. Ich habe den Code von jemanden übernommen.
Ich habe diesen Code eingestellt, weil dieser mir im debugger angezeigt wird, wenn ich in der entsprechenden Zeile einen Buchstaben habe.
Alternativ zur Anpassung des momentanen Codes:
Eine Möglichkeit wäre auch, ich mache mir in der UF eine zusätzliche Listbox, die mir den Inhalt einer Hilfszeile anzeigt. Und in dieser Hilfszeile übersetze ich die Zahl in einen Text.
Hallo,
beantwortet sehe ich keine meiner Fragen...Allerdings sind neue dazugekommen..
Zitat:Hallo,
beantwortet sehe ich keine meiner Fragen...Allerdings sind neue dazugekommen.
Weil ich es zum großen teil nicht beantworten kann. Ich habe kaum Erfahrungen in VBA. Einiges habe ich in letzter zeit gelernt, daher konnte ich auch vieles alleine ändern an der UF.
Aufgrund deiner Fragen, habe ich mir Überlegt, den Code lieber nicht anzupassen, da es ja wohl doch etwas umfangreicher zu werden scheint. Daher den gut laufenden Code lieber in Ruhe lassen.
Hallo,
(12.06.2017, 08:24)M.Wichmann schrieb: [ -> ]Weil ich es zum großen teil nicht beantworten kann. Ich habe kaum Erfahrungen in VBA.
Ohne Datei/vollständigen Code/Fehlermeldung kann ich dann leider auch nicht weiterhelfen.
Hilft das?
Code in der UF
Code:
Option Explicit
Private Sub CommandButton3_Click()
Call Auto7506
End Sub
Private Sub CommandButton4_Click()
Call Auto7509
End Sub
Private Sub CommandButton5_Click()
Call Auto7510
End Sub
Private Sub CommandButton6_Click()
Call Auto7517
End Sub
Private Sub LBArt_Change()
TBAnz.Value = ""
If LBDat.Value <> "" Then
For aBas = 1 To UBound(arrBas(), 1)
If CStr(arrBas(aBas, 1)) = LBDat.Value Then
For bBas = 1 To UBound(arrBas(), 2)
If CStr(arrBas(1, bBas)) = CStr(LBArt.Value) Then
TBAnz.Value = arrBas(aBas, bBas)
Exit For
End If
Next bBas
End If
If TBAnz.Value <> "" Then Exit For
Next aBas
End If
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub LBArt_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
With LBDat
.SetFocus
End With
End If
End Sub
Private Sub LBDat_Change()
TBAnz.Value = ""
If LBArt.Value <> "" Then
For aBas = 1 To UBound(arrBas(), 1)
If CStr(arrBas(aBas, 1)) = LBDat.Value Then
For bBas = 1 To UBound(arrBas(), 2)
If CStr(arrBas(1, bBas)) = CStr(LBArt.Value) Then
TBAnz.Value = arrBas(aBas, bBas)
Exit For
End If
Next bBas
End If
If TBAnz.Value <> "" Then Exit For
Next aBas
End If
End Sub
Private Sub CommandButton1_Click()
If LBArt.Value <> "" Then
For aBas = 1 To UBound(arrBas(), 1)
If CStr(arrBas(aBas, 1)) = LBDat.Value Then
For bBas = 1 To UBound(arrBas(), 2)
If CStr(arrBas(1, bBas)) = CStr(LBArt.Value) Then
arrBas(aBas, bBas) = TBAnz.Value
Exit For
End If
Next bBas
End If
Next aBas
End If
ws.Range(ws.Cells(3, 3), ws.Cells(lz, ls)) = arrBas
End Sub
Private Sub LBDat_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
With TBAnz
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
inddat2 = LBDat.ListIndex
End If
End Sub
Private Sub TBAnz_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then
If LBArt.Value <> "" Then
For aBas = 1 To UBound(arrBas(), 1)
If CStr(arrBas(aBas, 1)) = LBDat.Value Then
For bBas = 1 To UBound(arrBas(), 2)
If CStr(arrBas(1, bBas)) = CStr(LBArt.Value) Then
arrBas(aBas, bBas) = TBAnz.Value
Exit For
End If
Next bBas
End If
Next aBas
End If
ws.Range(ws.Cells(3, 3), ws.Cells(lz, ls)) = arrBas
KeyCode = 0
With TBAnz
.SelStart = 0
.SelLength = Len(.Text)
End With
End If
End Sub
Private Sub UserForm_Activate()
Call test
Me.LBDat.List = arrDat
Me.LBArt.List = arrArt
Me.LBDat.ListIndex = indDat + 1
End Sub
Code in Modul1
Code:
Option Explicit
Public arrBas() As Variant
Public arrDat() As Variant
Public arrArt() As Variant
Public ws As Worksheet
Public aBas As Integer
Public bBas As Integer
Public indDat As Long
Public inddat2 As Long
Public lz As Long
Public ls As Integer
Sub test()
Dim anz As Integer
Dim a As Integer
Dim b As Integer
Set ws = Worksheets("Lieferungen")
ls = ws.Cells(3, ws.Columns.Count).End(xlToLeft).Column
lz = ws.Cells(ws.Rows.Count, 3).End(xlUp).row
anz = Application.Count(ws.Range(ws.Cells(3, 5), ws.Cells(3, ls)))
ReDim arrBas(1 To lz, 1 To ls - 2)
ReDim arrDat(1 To lz)
ReDim arrArt(1 To anz)
arrBas = ws.Range(ws.Cells(3, 3), ws.Cells(lz, ls))
arrDat = ws.Range(ws.Cells(5, 3), ws.Cells(lz, 3))
For a = 5 To ls
If ws.Cells(3, a).Value <> "" Then
arrArt(b + 1) = ws.Cells(3, a).Value
b = b + 1
End If
Next a
For a = 1 To lz
If arrDat(a, 1) = Date Then
indDat = a
Exit For
End If
Next a
End Sub
Wie schon geschrieben, falls es einfacher sein sollte, kann auch gerne eine zusätzliche Listbox eingefügt werden, die auch eine Hilfszeile zugreift.
Hallo,
wo tritt denn jetzt bei welcher Aktion welcher Fehler auf?
wenn in Zeile 3 ein Buchstabe vorkommt ist hier ein Fehler
arrArt(b + 1)............ =gelb
Code:
For a = 5 To ls
If ws.Cells(3, a).Value <> "" Then
arrArt(b + 1) = ws.Cells(3, a).Value
b = b + 1
End If
Next a
Hallo,
(12.06.2017, 09:39)M.Wichmann schrieb: [ -> ]wenn in Zeile 3 ein Buchstabe vorkommt ist hier ein Fehler
Welcher Fehler? Du hast arrArt als Variant deklariert, das sollte eigentlich zu keinem Fehler führen.