2016-08-23 3 views
-1

Ich versuche, ein Makro einzufügen, die leere Werte in meiner Auswahl zählt und dann diese Zahl verwendet, um ein Makro zu wiederholen, um neue Blätter "Mycount" Anzahl von Zeiten einzufügen. Wie mache ich den zweiten Teil der Schleife? DankeVBA Loop-Funktion für n-mal

 'cnt blank cells in col U 
    Dim mycount As Long 
    mycount = Application.WorksheetFunction.CountBlank(Selection) 


    ‘add sheets for number of mycount 
    Dim looper as integer 
    Looper=mycount 
    Do while looper <=mycount 
    Sheets.add after:=ActiveSheet 
    Loop 
+2

Es gibt mehrere Varianten in [Dokumentation] (http://stackoverflow.com/documentation/vba/1873/flow-control- Strukturen # t = 201608231550302751355). – Comintern

Antwort

1

Diese zu Endlosschleife gehen. Sie benötigen eine Regelgröße

Do while looper <=mycount 
    Sheets.add after:=ActiveSheet 
    looper=looper +1 
Loop 
+1

Danke, hat super funktioniert! – TarasM

1

Ich denke, zu erhöhen, was Sie wollen ein For Loop ist.

Dim mycount As Long 
Dim i  as Long 
mycount = Application.WorksheetFunction.CountBlank(Selection) 

'This will add 'MyCount' number of sheets 
for i = 1 to myCount 
    Sheets.add after:=ActiveSheet 
Next i` 
1

Dies wird neue Blätter mycount Anzahl, wie oft hinzu:

Sub Test() 
Dim mycount As Long 
    mycount = Application.WorksheetFunction.CountBlank(Selection) 
For i = 1 To mycount 
    Sheets.Add after:=Sheets(Sheets.Count) 
Next i 
End Sub