我正在尝试使用VBA在Excel中添加一列用于序列号。
Column 1 Column 2
5 Xyz Data
6 Zyx Data
7 Yzx Data
我希望在第1列添加编号序列。
MySQL
此外,我想控制序列的起始位置。例如从5开始......
c#
感谢任何帮助。谢谢
答案 0 :(得分:0)
如果您正在处理A列的第1行到第100行,您可以尝试这样做:
Dim startNum As Long
Dim offNum As Long
Dim i As Long
Let startNum = InputBox("Start from:")
Let offNum = startNum - 1
For i = 1 To 100
ThisWorkbook.Sheets(1).Cells(i, 1).FormulaR1C1 = "=Row(R" & i & "C1) + " & offNum
Next
答案 1 :(得分:-1)
Sub enumeration()
Dim j, k As Integer
'determine the number to start with
j = Application.InputBox("What number should I start with?")
'determine how many rows are there to enumerate
k = Cells(1, 2).CurrentRegion.Rows.Count
For i = 0 To k - 2
Cells(i + 2, 1).Value = i + j
Next i
End Sub