2016-08-23 6 views
-1

空白の値を選択したマクロを挿入しようとしていますが、新しいシート "mycount"を挿入するためにマクロをループするためにそのカウントを使用します。 2番目のループ部分はどうすればいいですか?ありがとうございますn回回数のVBAループ機能

 '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

をhttp://stackoverflow.com/documentation/vba/1873/flow-control-構造体#t = 201608231550302751355)。 – Comintern

答えて

1

これは無限ループになります。あなたは私が何をしたいことはFor Loopだと思う

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

ありがとう、素晴らしい仕事! – TarasM

1

変数あなたのコントロールをインクリメントする必要があります。

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

これは新しいシートを何回mycount数追加されます:([ドキュメント]にはいくつかのバリエーションがあります

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