我正在尝试根据用户输入来打印以下内容(例如apple = 2,orange = 3):
(Cell C10): Apple 1
(Cell C11): Apple 2
(Cell C12): Orange 1
(Cell C13): Orange 2
(Cell C14): Orange 3
(Cell C15): Hello world 1
(Cell C16): Hello world 2
但是,当我运行脚本时,Apple 1输出到单元格C2。我需要修改什么才能将Apple 1打印到单元格C10?
我的代码如下:
Private Sub CommandButton1_Click()
Dim apple As Integer, orange As Integer
Dim i As Long, j As Long, k As Long, l As Long, lRow As Long, sentence1 As Long, sentence2 As Long
lRow = Cells(10, 3).End(xlUp).Row + 1
apple = InputBox("Please enter number of apples")
orange = InputBox("Please enter number of oranges")
sentence1 = 1
sentence2 = 1
For i = 1 To apple
Cells(lRow, 3) = "Apple " & i
lRow = lRow + 1
Next i
For j = 1 To orange
Cells(lRow, 3) = "Orange " & j
lRow = lRow + 1
Next j
For k = 1 To sentence1
Cells(lRow, 3) = "Hello world 1"
lRow = lRow + 1
Next k
For l = 1 To sentence2
Cells(lRow, 3) = "Hello world 2"
lRow = lRow + 1
Next l
End Sub
当您执行End(xlUp)
与Ctrl + Up相同的操作时,您将在更改行。如果要排10,那就去做lRow=10
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句