如何在 excel 中的两个给定编号之间生成列表



请帮助生成具有两个否的列表系列的技巧。

例如:

有这样的数据:

Key      | Month | Year | Location | From | To    
HYE000001| 12    |2013  | 91       | 01   | 52

并希望输出采用以下格式:

Key      | Month | Year | Location
HYE000001| 12    | 2013 | 91
HYE000002| 12    | 2013 | 91
HYE000003| 12    | 2013 | 91
HYE000004| 12    | 2013 | 91
.
.
.
HYE000051| 12    | 2013 | 91
HYE000052| 12    | 2013 | 91

请帮助我解决问题

谢谢。

  • 希文

在这里,我尝试使用宏并且对我来说效果很好。下面的代码片段将仅适用于键值,您可以根据需要对其进行修改。

将键值放在 A2 单元格中,将 From 值放在 B2 单元格中,将 To 值放在 C2 单元格中,然后尝试运行以下代码。

Sub KeyGenerator()
'From range defined in B2 Cell
Dim From As Integer
From = Range("B2").Value
'To range defined in C2 Cell
Dim Till As Integer
Till = Range("C2").Value
'Here A2 cell will have the primary key and modifying the A2 cell value using From value.
Dim LastKey As String
Dim Key, Current As String
Current = Range("A2").Value
Key = Left(Current, Len(Current) - 1)
Key = Key & From
Range("A2").Value = Key
'Dragging values using To value
Range("A2").Select
LastKey = "A" & ((Till - From) + 2)
Selection.AutoFill Destination:=Range("A2:" & LastKey), Type:=xlFillDefault
End Sub

最新更新