如何取消 VBA 中的数据
How to un-flatten data in VBA
我是 VBA 的新手,并试图在 Google 上寻求帮助但没有成功,此外,我不知道要搜索以下问题的内容。
下面是我的工作表示例,它包含超过 2500 行,需要取消展平
A | B | C | D
Text1 | Dummy1 | 1 | Power1
Text1 | Dummy1 | 1 | Power2
Text1 | Dummy2 | 1 | Power1
Text3 | Dummy3 | 1 | Power1
Text3 | Dummy3 | 1 | Power2
我正在寻找 VBA 中的解决方案以获得以下格式的结果
A | B | C | D
Text1 | Dummy1 | 2 | Power1 Power2
Text1 | Dummy2 | 1 | Power1
Text3 | Dummy3 | 2 | Power1 Power2
如果 (A1,B1) 等于 (A2,B2),则计数 1+1 并将 D1 单元格的内容替换为 D1+D2(POWER1 和 POWER2(同一单元格中的新行))
我想知道是否有人知道该怎么做或它叫什么?
谢谢!
你很幸运,因为我很无聊...这样我会扔给你一些代码行来做你想做的事。但作为一个缺点(比如对不显示代码的小惩罚),我让它变得缓慢且难以阅读:P
Sub test()
Dim a(2) As Range
Set a(0) = ActiveSheet.Range("A2:D2")
While a(0)(1).Value <> ""
Set a(1) = a(0).Offset(1)
Set a(2) = Nothing
While a(1)(1).Value <> ""
If a(0)(1).Value = a(1)(1).Value And a(0)(2).Value = a(1)(2).Value Then
a(0)(3).Value = a(0)(3).Value + a(1)(3).Value
a(0)(4).Value = a(0)(4).Value & " " & a(1)(4).Value
If a(2) Is Nothing Then
Set a(2) = a(1)
Else
Set a(2) = Union(a(2), a(1))
End If
End If
Set a(1) = a(1).Offset(1)
Wend
If Not a(2) Is Nothing Then a(2).EntireRow.Delete xlUp
Set a(0) = a(0).Offset(1)
Wend
End Sub
不过,如果有任何问题,请随时询问 ;)
我是 VBA 的新手,并试图在 Google 上寻求帮助但没有成功,此外,我不知道要搜索以下问题的内容。
下面是我的工作表示例,它包含超过 2500 行,需要取消展平
A | B | C | D
Text1 | Dummy1 | 1 | Power1
Text1 | Dummy1 | 1 | Power2
Text1 | Dummy2 | 1 | Power1
Text3 | Dummy3 | 1 | Power1
Text3 | Dummy3 | 1 | Power2
我正在寻找 VBA 中的解决方案以获得以下格式的结果
A | B | C | D
Text1 | Dummy1 | 2 | Power1 Power2
Text1 | Dummy2 | 1 | Power1
Text3 | Dummy3 | 2 | Power1 Power2
如果 (A1,B1) 等于 (A2,B2),则计数 1+1 并将 D1 单元格的内容替换为 D1+D2(POWER1 和 POWER2(同一单元格中的新行))
我想知道是否有人知道该怎么做或它叫什么?
谢谢!
你很幸运,因为我很无聊...这样我会扔给你一些代码行来做你想做的事。但作为一个缺点(比如对不显示代码的小惩罚),我让它变得缓慢且难以阅读:P
Sub test()
Dim a(2) As Range
Set a(0) = ActiveSheet.Range("A2:D2")
While a(0)(1).Value <> ""
Set a(1) = a(0).Offset(1)
Set a(2) = Nothing
While a(1)(1).Value <> ""
If a(0)(1).Value = a(1)(1).Value And a(0)(2).Value = a(1)(2).Value Then
a(0)(3).Value = a(0)(3).Value + a(1)(3).Value
a(0)(4).Value = a(0)(4).Value & " " & a(1)(4).Value
If a(2) Is Nothing Then
Set a(2) = a(1)
Else
Set a(2) = Union(a(2), a(1))
End If
End If
Set a(1) = a(1).Offset(1)
Wend
If Not a(2) Is Nothing Then a(2).EntireRow.Delete xlUp
Set a(0) = a(0).Offset(1)
Wend
End Sub
不过,如果有任何问题,请随时询问 ;)