答案 0 :(得分:2)
你需要2个循环。一个循环通过A列,一个计数到B列中的值。
Option Explicit
Public Sub WriteValues()
With Worksheets("Sheet1")
Dim aLastRow As Long
aLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'get last used row in col A
Dim dRow As Long
dRow = 1 'start row in col D
Dim aRow As Long
For aRow = 1 To aLastRow 'loop through col A
Dim bCount As Long
For bCount = 1 To .Cells(aRow, "B").Value 'how many times is A repeated?
.Cells(dRow, "D").Value = .Cells(aRow, "A") & "_" & bCount 'write into column D
dRow = dRow + 1 'count rows up in col D
Next bCount
Next aRow
End With
End Sub
答案 1 :(得分:0)
您的要求在细节方面略有不足,但这样做可以满足您的要求。
dim i as long
with worksheets("sheet1")
for i=1 to .cells(2, "B").value2
.cells(.rows.count, "D").end(xlup).offset(1, 0) = .cells(2, "A").value & format(i, "\_0")
next i
end with