在这个例子中,我使用Dim关键字定义了一个包含五个字符串的数组StudentName。我包含一个InputBox来接受来自用户的输入。我还使用For ... Next循环接受输入五次并显示从单元格A1到单元格E1的五个名称。代码如下:
Sub CommandButton1_Click( )
Dim StudentName(1 to 5) As String
For i = 1 To 5
StudentName(i) = InputBox("Enter student Name")
Cells(i, 1) = StudentName(i)
Next
End Sub
我如何在GAP OF 10 CELLS中显示这5个名字:A30到A40到A50等等?
答案 0 :(得分:0)
将数组维度更改为从零开始,并使用迭代var(i
)作为乘数。
Sub CommandButton1_Click( )
Dim StudentName(0 to 4) As String
For i = lbound(StudentName) To ubound(StudentName)
StudentName(i) = InputBox("Enter student Name")
Cells(30 + i * 10, 1) = StudentName(i)
Nexti
End Sub