Ich habe folgende Makros
Public i As Variant
_____________________________________________________________
Private Sub CommandButton11_Click()
i = 5
cap = Application.VLookup(i, Sheets("Produkte").Range("A2:B500"), 2, False)
CommandButton11.Caption = cap
Call anzeige
End Sub
_____________________________________________________________
Die Variable i soll nun an das folgende Makro übergeben werden.
Public i As Variant
______________________________________________________________
Sub anzeige()
Dim anz As Variant, gef As Variant, i As Variant
Sheets("Eingabe").Select
gef = Application.Match("Summe", Rows("2:2"), 0)
If (IsError(gef)) Then GoTo line
If gef >= 1 Then
Range("A2:F" & gef).Clear
End If
line:
anz = Sheets("Eingabe").Range("A" & Rows.Count).End(xlUp).Row + 1
If IsEmpty(Cells(anz, 2)) Then
Cells(anz, 2) = 1
End If
Cells(anz, 1) = i 'suchkürzel
Cells(anz, 1).HorizontalAlignment = xlCenter
Cells(anz, 2).HorizontalAlignment = xlCenter
Cells(anz, 3) = Application.VLookup(Cells(anz, 1), Sheets("Produkte").Range("A1:D500"), 2, False) 'Bezeichnung
Cells(anz, 4) = Application.VLookup(Cells(anz, 1), Sheets("Produkte").Range("A1:D500"), 3, False) 'Einzelpreis
Cells(anz, 4).NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
Cells(anz, 4).Select
With Selection
.HorizontalAlignment = xlLeft
.Font.Size = 8
.NumberFormat = "$#,##0.00_);[Red]($#,##0.00)"
End With
Call zwSumme
End Sub
Wie übergebe ich nun die die Varible i an das Folgemakro?
Ich habe insgesamt 30 CommandButton.
Die zugehörigen Private Sub unterscheiden sich nur in der Variablen i.
i hat den Wert von 1 bis 30.
Internetsuchen haben dazu geraten Public i As Variant zu nutzen.
Funktioniert aber nicht wie gewünscht.
Viele Grüße
Jörg