VBA For循环不打印值到单元格

Option Explicit Public Sub Autoserial() Dim a As Long Dim b As Long Dim c As Long Dim d As Long Dim e As Long a = Selection.Row b = Selection.Rows.Count + Selection.Row - 1 c = Selection.Column d = 1 For e = a To e = b Cells(e, c).Value = d d = d + 1 Next e End Sub 

此代码是手动排名function。 当我运行这个代码时,序列号应该出现在select的第一列。 没有什么打印在该列上。 另外,没有错误显示。

select是A1到D5

请尝试这个,我整理并删除了一些不需要的variables,这应该打印您的序列号在您的select的第一列

 Option Explicit Public Sub Autoserial() Dim iRowStart As Long Dim iRowEnd As Long Dim iCol As Long, iRow as long Dim iIncrement As Long iRowkStart = Selection.Row iRowEnd = Selection.Rows.Count + Selection.Row - 1 iCol = Selection.Column iIncrement = 1 For iRow =iRowStart to iRowEnd Cells(iRow, iCol).Value = iIncrement iIncrement = iIncrement + 1 Next iRow End Sub