Vba variablen deklaration definition wie
Also ich habe das folgende Problem. Meine Skripts sind ohne Variablen. Leider muss ich häufiger einige Spalten in Excel hinzufügen, somit stimmen meine Skripts dann nicht mehr und müssen wieder angepasst werden. Damit ich nicht alles wieder machen muss, will ich Variablen verwenden.
Ein Ausschnitt aus meinem Skript:
Private Sub Worksheet_Change
For Counter = 1 To 65536
If Cells > "0" Then
Application.EnableEvents = False
Cells.Interior.ColorIndex = 3
Cells.Font.ColorIndex = 1
.
End If
Next
So sieht mein Skript aus. Das ist natürlich nur ein kleiner Ausschnitt.
Wenn ich nun das Skript mit Variablen fülle würde es im Beispiel so aussehen:
Private Sub Worksheet_Change
Dim A as Variant
Dim B as Variant
For Counter = 1 To 65536
A = Cells
B = Cells
If A > "0" Then
Application.EnableEvents = False
B.Interior.ColorIndex = 3
B.Font.ColorIndex = 1
.
End If
Next
Jetzt wäre meine Frage, was hier nicht stimmt. Wird das ganze Skript so umgesetzt, funktioniert es nicht mehr. Kann mir jemand einen Vorschlag machen, wie ich das zum Laufen bekomme?
schonmal für
Antworten zur Frage
Videos zum Thema
YouTube Videos
VBA: Variablen Deklaration und Definition - Wie?
z.B. könntest Du das so probieren
Private Sub Worksheet_Change
dim lngA as long, lngB as long
lngA = 8
lngB = 9
For Counter = 1 To 65536
If Cells > "0" Then
Application.EnableEvents = False
Cells.Interior.ColorIndex = 3
Cells.Font.ColorIndex = 1
.
End If
Next