我试图将数据输入到列b,转到列c依次
我怎么能这样做是我的代码请帮助我...
Sub ()
Dim Continue As String
Continue = "Go"
Do While Continue = "Go"
Dim Message As String
Dim Answer As String
Message = "enter name"
Answer = inputbox(Message)
ActiveSheet.Range("B1").Value = (Answer)
If ActiveSheet.Range("B2") = "yes" then
activesheet.range("B10").value="good"
Else
ActiveSheet.Range("B10").Value = "no good"
End If
Continue = InputBox("Do you want to continue?")
Loop
End Sub
每次循环时,它都会继续在列c中插入数据,我希望在列c中
你可以编辑我的剧本..
提前致谢
答案 0 :(得分:0)
当你写:ActiveSheet.Range("B1").Value = (Answer)
时,“B1”是字面意思;它永远不会改变。
Range
的参数是一个String,您可以在运行时构建该字符串:
Dim ColumnIdCrnt as String
Dim RowCrnt as Long
ColumnIdCrnt = "B"
RowCrnt = 1
ActiveSheet.Range(ColumnIdCrnt & RowCrnt).Value = (Answer)
这不是最简单的方法,但它是可能的。
而不是Range
使用Cells
。语法为Cells(Row, Column)
,其中Row
必须是行号,Column
可以是列标识符或列号。以下都是等效的:
ActiveSheet.Range("B1").Value
ActiveSheet.Cells(1, "B").Value
ActiveSheet.Cells(1, 2).Value
列号和列标识符之间的关系是:1 =“A”,2 =“B”,3 =“C”,26 =“Z”,27 =“AA”等等。
所以你可以这样写:
ColNumCrnt as Long
ColNumCrnt = 1
Do While Continue = "Go"
‘ Process input using column ColNumCrnt
ActiveSheet.Range(ColNumCrnt & "1").Value = (Answer)
ColNumCrnt = ColNumCrnt + 1 ‘ Move one column to the right ready for next loop
Loop