For statement

Status
Niet open voor verdere reacties.

Bergsma1

Gebruiker
Lid geworden
7 feb 2012
Berichten
40
Ik wil het volgende script 37 keer laten itereren maar er gebeurt niks,
Feitelijk wil ik dat de sheet schoon gemaakt word in bepaalde bereiken, CS tot JE, waarbij begin S en eind E variabel zijn.
Maar het script lijkt niet te lopen. Wat doe ik nog verkeerd?

Code:
Sub Macro1()


Application.ScreenUpdating = False
Application.Calculation = xlManual

Dim S As Integer
Dim E As Integer
Dim I As Integer


S = 21
E = 28

For I = 1 To I = 37

            Sheets("XX).Range("C" & S & ":J" & E).Select
            Selection.ClearContents
            
        
            S = S + 13
            E = E + 13
            I = I + 1
            
Next I

Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
        
    End Sub
 
die I = I +1 kan er sowieso uit, dit doe je al met next

+ select en dus selection zijn ook overbodig
 
Deze regel is fout:

Code:
For I = 1 To I = 37

Gebruik F8 in de VBEditor.
 
Verder kan het ook wel wat netter:
Code:
Sub Macro1()
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    S = 21
    E = 28

    For I = 1 To 37
        Sheets("XX").Range("C" & S & ":J" & E).ClearContents
        Selection.ClearContents
        S = S + 13
        E = E + 13
    Next I

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
 
Laatst bewerkt:
@edm

Geen specsavers om de hoek ? :p

Code:
        Selection.ClearContents
 
Bril zat scheef ;)
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan