我有一个excel表,其中包含以下列:
ID# Name From To
ASB0001 Adams 1 3
ASB0002 Robert 4 5
是否有任何代码在序列号之间生成,如下所示:
ASB0001 Adams 1
ASB0001 Adams 2
ASB0001 Adams 3
ASB0002 Robert 4
ASB0002 Robert 5
请注意该表包含约46000条记录。非常感谢您的支持,谢谢
答案 0 :(得分:0)
如果您想使用VBA:
Range("G:I").Clear
k = 0
For i = 2 To 99999
If Range("A" & i).Value = "" Then Exit For
For e = Range("C" & i).Value To Range("D" & i).Value
k = k + 1
Range("G" & k).Value = Range("A" & i).Value
Range("H" & k).Value = Range("B" & i).Value
Range("I" & k).Value = e
Next
Next
考虑数据从 A2 开始到 Dn (小于99999)。
数据从单元格 G1 扩展到单元格 Ix
如果您不想要VBA,请添加公式:
G2 -> =IF(P2<>"";INDEX($A$2:$A$15;MATCH(ROW(M1);$C$2:$C$4;1));"")
H2 -> =IF(P2<>"";INDEX($B$2:$B$15;MATCH(ROW(M1);$C$2:$C$4;1));"")
I2 -> =IF(ROW(P1)>MAX(D:D);"";ROW(P1))
如果号码是连续的,工作。
答案 1 :(得分:0)
尝试这个小宏:
Sub ReOrganizer()
Dim s1 As Worksheet, s2 As Worksheet, _
N As Long, i As Long, M As Long, _
F As Long, T As Long, ID As String, _
Nam As String, j As Long
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet2")
N = s1.Cells(Rows.Count, "A").End(xlUp).Row
M = 1
For i = 2 To N
ID = s1.Cells(i, 1).Value
Nam = s1.Cells(i, 2).Value
F = s1.Cells(i, 3).Value
T = s1.Cells(i, 4).Value
For j = F To T
s2.Cells(M, 1).Value = ID
s2.Cells(M, 2).Value = Nam
s2.Cells(M, 3).Value = j
M = M + 1
Next j
Next i
End Sub
假设原始数据位于 Sheet1 中,输出位于 Sheet2中。