怎样用VBA做loop循环?

要从第一周循环到第十八周(也就是只要改一下week的数字),怎么用inputbox加loop循环?

看了你的代码之后,我感觉这代码是用宏录制功能生成的吧,我感觉使用相对引用的方式,很快就会把自己绕晕了!建议给单元格赋值的时候直接使用cells(1,2).value="值"这样的方式,其中“1”指的是行数,“2”指的是列数。我简单写了全部代码,直接就可以运行:

Sub 计划表()
  Dim a As Integer
  a = InputBox("Enter the number of weeks")
  
  Dim x As Integer
  For i = 1 To a
    x = (i - 1) * 10
    '第1列
    Cells(x + 1, 1).Value = "Week"
    Cells(x + 2, 1).Value = Str(i) '周数
    Cells(x + 3, 1).Value = ""
    Cells(x + 4, 1).Value = ""
    Cells(x + 5, 1).Value = ""
    Cells(x + 6, 1).Value = ""
    Cells(x + 7, 1).Value = ""
    Cells(x + 8, 1).Value = ""
    Cells(x + 9, 1).Value = ""
    Cells(x + 10, 1).Value = ""
    
    '第2列
    Cells(x + 1, 2).Value = "Days"
    Cells(x + 2, 2).Value = "Monday"
    Cells(x + 3, 2).Value = ""
    Cells(x + 4, 2).Value = "Tuesday"
    Cells(x + 5, 2).Value = ""
    Cells(x + 6, 2).Value = "Wednesday"
    Cells(x + 7, 2).Value = ""
    Cells(x + 8, 2).Value = "Thursday"
    Cells(x + 9, 2).Value = ""
    Cells(x + 10, 2).Value = "Friday"
    
    '第3列
    Cells(x + 1, 3).Value = "Subjects"
    Cells(x + 2, 3).Value = "Math"
    Cells(x + 3, 3).Value = "Financial Accounting"
    Cells(x + 4, 3).Value = "Micro Economics"
    Cells(x + 5, 3).Value = "AI"
    Cells(x + 6, 3).Value = "Math"
    Cells(x + 7, 3).Value = "English"
    Cells(x + 8, 3).Value = "Computer"
    Cells(x + 9, 3).Value = "China"
    Cells(x + 10, 3).Value = "Computer"
    
    '第4列
    Cells(x + 1, 4).Value = "Lecture duration"
    Cells(x + 2, 4).Value = "1.5"
    Cells(x + 3, 4).Value = "1.5"
    Cells(x + 4, 4).Value = "1.5"
    Cells(x + 5, 4).Value = "1.5"
    Cells(x + 6, 4).Value = "1.5"
    Cells(x + 7, 4).Value = "1.5"
    Cells(x + 8, 4).Value = "1.5"
    Cells(x + 9, 4).Value = "1.5"
    Cells(x + 10, 4).Value = "1.5"
    
    '第5列
    Cells(x + 1, 5).Value = "Revise classnotes"
    Cells(x + 2, 5).Value = "1"
    Cells(x + 3, 5).Value = "1"
    Cells(x + 4, 5).Value = "1"
    Cells(x + 5, 5).Value = "1"
    Cells(x + 6, 5).Value = "1"
    Cells(x + 7, 5).Value = "1"
    Cells(x + 8, 5).Value = "1"
    Cells(x + 9, 5).Value = "1"
    Cells(x + 10, 5).Value = "1"
    
    '第6列
    Cells(x + 1, 6).Value = "Assignments"
    Cells(x + 2, 6).Value = "1"
    Cells(x + 3, 6).Value = "1"
    Cells(x + 4, 6).Value = "1"
    Cells(x + 5, 6).Value = "1"
    Cells(x + 6, 6).Value = "1"
    Cells(x + 7, 6).Value = "1"
    Cells(x + 8, 6).Value = "1"
    Cells(x + 9, 6).Value = "1"
    Cells(x + 10, 6).Value = "1"
    
    '第7列
    Cells(x + 1, 7).Value = "Self study"
    Cells(x + 2, 7).Value = "1"
    Cells(x + 3, 7).Value = "1"
    Cells(x + 4, 7).Value = "1"
    Cells(x + 5, 7).Value = "1"
    Cells(x + 6, 7).Value = "1"
    Cells(x + 7, 7).Value = "1"
    Cells(x + 8, 7).Value = "1"
    Cells(x + 9, 7).Value = "1"
    Cells(x + 10, 7).Value = "1"
  
  Next
End Sub

运行的效果图:

 

比如问题中上面那个图,是要从第一周循环到第十八周(也就是只要改一下week的数字),怎么用inputbox加loop循环?