[英]Number down a column based on amount of rows from another column
I am trying to number column A in increments by 1, based on how many rows are in column B Example of my Excel sheet我正在尝试根据 B 列中有多少行,以 1 为增量对 A 列进行编号我的 Excel 工作表示例
The code I currently have does this, but the top number does not end up being 1. I need to start with 1 at the top and count down.我目前拥有的代码可以做到这一点,但顶部的数字最终不会是 1。我需要从顶部的 1 开始并倒计时。
Sub SecondsNumbering()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Data Formatted")
Dim LastRow As Long
Dim i As Long
With ws
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For i = 6 To LastRow
.Cells(i, 1).Value = i - 1
Next
End With
End Sub
With this, I am counting the number of rows in the column.有了这个,我正在计算列中的行数。
Edit: When I do the value 7 for i, so that it starts at 6 (which is where I want data to start) this is what I get.编辑:当我为 i 执行值 7 时,它从 6 开始(这是我希望数据开始的地方),这就是我得到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.