需要一个vbamacros来创build一个基于起始数字和块大小的单列数据

对不起,这可能是一个特定的任务,我没有太多的使用其他人。 我在网站上发现了一些代码,我已经能够适应我的数据分为一列,但我仍然需要手动创build起点,这需要我几个小时。

基本上,我的系统导出一个备用用户ID的报告,而不是列出所有我得到的A列的第一个数字,并在B列在该块可用的ID号码。

所以我期待得到……

AB 100 4 120 1 130 3 156 4 

至…..

 A 100 101 102 103 120 130 131 132 156 157 158 159 

任何帮助非常感谢你。

格伦

 Sub BreakOutIDs() Dim vaInput As Variant Dim aOutput() As Long Dim i As Long, j As Long Dim lCnt As Long 'put existing table into an array vaInput = Sheet1.Range("A1:B4").Value 'loop through "column A" For i = LBound(vaInput, 1) To UBound(vaInput, 1) 'loop through as many values as in "column B" For j = 0 To vaInput(i, 2) - 1 'increase the output array size and put the value in it 'redim only lets you increase the last part of an array lCnt = lCnt + 1 ReDim Preserve aOutput(1 To 1, 1 To lCnt) aOutput(1, lCnt) = vaInput(i, 1) + j Next j Next i 'transpose the array from a row to a column and write to column D Sheet1.Range("D1").Resize(UBound(aOutput, 2), 1).Value = Application.WorksheetFunction.Transpose(aOutput) End Sub 

我把输出放在列D而不是A,所以它不会覆盖你现有的数据。 它会覆盖D中的数据,所以调整最后一行放到你想要的地方。 另外,调整vaInput线以获得您的实际input范围。