Excelシート 繰り返し処理
シートへの処理を繰り返したいのですが、うまくいきません。
下記処理をシート5まで繰り返したいです。
次のシートに移る際、「rs_1」の数字を1つ増やしたいです。
該当のソースコード
VBA
1With Worksheets("シート名1") 2 .Cells.Clear 3 rs_1.MoveFirst 4 i = 1 5 .Cells.Clear 6 Do Until rs_1.EOF = True 7 For j = 0 To rs_1.Fields.Count - 1 8 If i = 1 Then .Cells(i, j + 1) = rs_1(j).Name 9 .Cells(i + 1, j + 1) = rs_1(j).Value 10 Next j 11 rs_1.MoveNext 12 i = i + 1 13 Loop 14.Columns("A:H").AutoFit 15End With
試したこと
VBA
1For SheetNum = 1 To 5 2Sheets(SheetNum).Select 3 Num = 1 4 With Worksheets(SheetNum) 5 .Cells.Clear 6 rs_Num.MoveFirst 7 i = 1 8 .Cells.Clear 9 Do Until rs_Num.EOF = True 10 For j = 0 To rs_Num.Fields.Count - 1 11 If i = 1 Then .Cells(i, j + 1) = rs_Num(j).Name 12 .Cells(i + 1, j + 1) = rs_Num(j).Value 13 Next j 14 rs_Num.MoveNext 15 i = i + 1 16 Loop 17 .Columns("A:H").AutoFit 18 Num = Num + 1 19 End With 20Next SheetNum
ここにより詳細な情報を記載してください。
あなたの回答
tips
プレビュー