【发布时间】:2020-10-07 18:42:53
【问题描述】:
我的数据集有数千行,组合从 1 个单元格到 15 个单元格不等。
每个组合都由一个空白单元格分隔。
我希望 VBA 在整个专栏中自动执行此过程。
Sub Concat()
Dim i As Integer, Sht As Worksheet, Str As String
i = 3
Set Sht = ThisWorkbook.Sheets(2)
Str = Sht.Cells(2, 1).Value
Do Until Sht.Cells(i, 1).Value = "999999"
Do Until Sht.Cells(i, 1).Value = ""
Str = Str & "-" & Sht.Cells(i, 1).Value
i = i + 1
Loop
Sht.Cells(i, 1).Value = Str
'Here i need the string to reset and start over
' at the cell under the cell where stringvalue was pasted
Loop
End Sub
【问题讨论】:
-
为什么将单元格的值更改为
Str,然后将Str的值更改为刚刚更改的单元格的值?Str = Sht.Cells(i, 1).Value -
@K.Dᴀᴠɪs 我在这里深水...试图重新提出我的问题,你能帮我吗?