excel - 如何在 Microsoft excel 中相对于变量重复数据?
问题描述
嗨,我有一个名称列表和一个变量,我需要一个 Excel 公式或插件或自动化方法来根据变量中的数字重复名称。我需要一个公式来自动化输出列,例如:
解决方案
可能尽可能干净。有一个For
循环和Do Until
循环给你选择。
Sub repeat()
' define varible types
Dim i, n As Integer
Dim wb As Workbook: Set wb = Workbooks(ThisWorkbook.Name)
Dim ws As Worksheet: Set ws = wb.Worksheets("Sheet1")
Dim LastRow As Long
' initialize variables
n = 1
i = 1
' do loop until empty cell is found in column 1 (A)
Do Until IsEmpty(ws.Cells(i, 1))
' second loop to define number of iterations
For n = 1 To ws.Cells(i, 2)
' find last row to keep adding to the bottom of the list
LastRow = ws.Cells(ws.Rows.Count, "C").End(xlUp).Row
' populate list
ws.Cells(LastRow + 1, 3) = ws.Cells(i, 1)
Next
i = i + 1
Loop
End Sub
推荐阅读
- python - 使用 Selenium Python 的新选项卡
- flutter - Flutter中如何设计这种类型的句子?
- visual-studio - 如果 MSVS 局部变量窗口展开“this->base”视图,变量将状态更改为相反
- uwp - 当 MediaTransportContols.IsCompact 为 True 时,UWP MediaPlayerElement 奇怪的播放按钮外观
- neo4j - 我在将批量数据从 CSV 文件导入 neo4j 桌面时遇到问题。我将内存堆增加到 8G 但无法导入数据
- xaml - 为 Uno 平台嵌入图像到 Wasm
- typescript - 获取泛型对象中已知属性的类型
- swift - 如何在 NSStatusBar 中绘制自定义视图?
- c++ - TSharedPtr 全局变量
- javascript - 通过索引从 Jquery 选择器中获取元素