我在 excel 中有两列,如下所示
a,苹果
a,香蕉
a,橙
a,李子
b,苹果
b,浆果
b,橙
b,柚子
c,甜瓜
c,浆果
c,猕猴桃
我需要像这样将它们合并到另一张纸上
a、苹果、版纳纳、橙、李子
b、苹果、浆果、橙、柚子
c、甜瓜、浆果、猕猴桃
任何帮助,将不胜感激
此代码有效,但速度太慢。我必须循环浏览 300000 个条目。
Dim MyVar As String
Dim Col
Dim Var
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
' Select first line of data.
For Var = 1 To 132536
Sheets("Line Item Detail").Select
Range("G2").Select
' Set search variable value.
Var2 = "A" & Var
MyVar = Sheets("Sheet1").Range(Var2).Value
'Set Do loop to stop at empty cell.
Col = 1
Do Until IsEmpty(ActiveCell)
' Check active cell for search value.
If ActiveCell.Value = MyVar Then
Col = Col + 1
Sheets("Sheet1").Range(Var2).Offset(0, Col).Value = ActiveCell.Offset(0, 1).Value
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
Next Var
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True