hab ne Frage insbesondere zu ner Schleife:
Wie mach ich das mit VBA , dass er die schleife so zählen lässt:
Dim i As Integer
For i = 42 To 79 Step 2
Aber, er soll wieder bei 90 weitermachen und bei 115 wieder aufhören.
Wie mach ich das?
Dim i As Integer
For i = 42 To 79 Step 2
Aber, er soll wieder bei 90 weitermachen und bei 115 wieder aufhören.
Wie mach ich das?
param1=42
param2=79
param3=2
gosub mach
param1=90
param2=115
param3=2
gosub mach
exit sub
mach:
for i=param1 to param2 step param3
...
next
return
ich würde folgende zwei Schleifen verwenden.
Dim i As Integer
For i = 42 To 79 Step 2
msubTueWas(arg1.....)
next i
for i = 90 to 115 step 2
msubTueWas(arg1...)
next i
private sub msubTueWas(arg1.....)
'hier den code, was ausgeführt werden soll
.....
end sub
Sonst fällt mir auch keine Lösung ein.
Gruß
Frank
Entweder nutz mal den Debugger
Oder füg mal MSGBOXen ein
Oder gib mehr Information (z.B. die Quelle !!!)
Private Sub CommandButton1_Click()
Zielwert = Application.WorksheetFunction.Sum(Range("I42:I999"))
If Zielwert > "-1" Then
Zielwert = Format(Zielwert, "#,##0.00")
End If
If Zielwert > "1" Then
Zielwert = Format(Zielwert, "#,##0.0")
End If
If Zielwert > "10" Then
Zielwert = Format(Zielwert, "#,##0")
End If
If Zielwert = 0 Then
Range("d31").Value = "0"
Else
Range("d31").Value = Zielwert
End If
End Sub
Private Sub ersetzen_Click()
Dim i As Integer
param1 = 42
param2 = 79
param3 = 2
GoSub mach
param1 = 90
param2 = 115
param3 = 2
GoSub mach
Exit Sub
mach:
For i = param1 To param2 Step param3
If Cells(12, 3).Value <= 15 = True Then
If Cells(i, 9).Value < 1 = True And Not (Cells(i, 9).Value = "") And Not (Cells(i, 9).Value = 0#) Then
Cells(i, 9).Value = 1
Cells(i, 8).Value = "<"
ElseIf Cells(i, 9).Value > 1 = True And Not (Cells(i, 9).Value = "") And Not (Cells(i, 9).Value = 0#) Then
Cells(i, 8).Value = ""
End If
ElseIf Cells(12, 3).Value <= 50 = True And Cells(12, 3).Value > 15 = True Then
If Cells(i, 9).Value < 0.3 = True And Not (Cells(i, 9).Value = "") And Not (Cells(i, 9).Value = 0#) Then
Cells(i, 9).Value = 0.3
Cells(i, 8).Value = "<"
ElseIf Cells(i, 9).Value > 0.3 = True And Not (Cells(i, 9).Value = "") And Not (Cells(i, 9).Value = 0#) Then
Cells(i, 8).Value = ""
End If
ElseIf Cells(12, 3).Value <= 150 = True And Cells(12, 3).Value > 50 = True Then
If Cells(i, 9).Value < 0.1 = True And Not (Cells(i, 9).Value = "") And Not (Cells(i, 9).Value = 0#) Then
Cells(i, 9).Value = 0.1
Cells(i, 8).Value = "<"
ElseIf Cells(i, 9).Value > 0.1 = True And Not (Cells(i, 9).Value = "") And Not (Cells(i, 9).Value = 0#) Then
Cells(i, 8).Value = ""
End If
ElseIf Cells(12, 3).Value > 150 = True Then
If Cells(i, 9).Value < 0.05 = True And Not (Cells(i, 9).Value = "") And Not (Cells(i, 9).Value = 0#) Then
Cells(i, 9).Value = 0.05
Cells(i, 8).Value = "<"
ElseIf Cells(i, 9).Value > 0.05 = True And Not (Cells(i, 9).Value = "") And Not (Cells(i, 9).Value = 0#) Then
Cells(i, 8).Value = ""
End If
End If
Next i
End Sub
Private Sub Image_Click()
Dim filename As Variant
filename = Application.GetOpenFilename("JPEG (*.jpg),*.bmp,AlleDateien,*.*", 1, "Bild auswählen")
If filename <> False Then
Image.Picture = LoadPicture(filename)
End If
End Sub
Private Sub Sichtbar_Change()
If Sichtbar.Value = False Then
Range("g36").Select
Selection.Font.ColorIndex = 2
End If
If Sichtbar.Value = False Then
Range("i36").Select
Selection.Font.ColorIndex = 2
End If
If Sichtbar.Value = True Then
Range("g36").Select
Selection.Font.ColorIndex = 1
End If
If Sichtbar.Value = True Then
Range("i36").Select
Selection.Font.ColorIndex = 1
End If
Dim i As Integer
For i = 40 To 118
If Sichtbar.Value = False Then
Cells(i - 1, 10).Select
Selection.Font.ColorIndex = 2
Else
If Sichtbar.Value = True Then
Cells(i - 1, 10).Select
Selection.Font.ColorIndex = 1
End If
End If
Next i
Sichtbar.Select
End Sub
Das ist das ganze programm, reichen die Infos?
Ich hätte schreiben sollen
nutz mal den Debugger
Wenn Du nicht weiter kommst dann
füg mal MSGBOXen ein
Wenn Du nicht weiter kommst dann
gib mehr Information (z.B. die Quelle !!!)
Durch das alles steige ich leider nicht. Sorry
wenn ich das jetzt richtig überflogen habe fehlt das return!!
So muß es heißen
Next i
Return
End Sub
Der Return bewirkt daß er nach dem Gosub wieder weitermacht ... von daher müßte die nächste "Parameter-Staffel" dann auch durchlaufen ...
Probiers mal ...
Gruß
Robert