我是VBA的新手,如果可能,请提供一些帮助。我有50行数据,有4个不同的车名(FIAT,SEAT,MINI,VOLVO),我想分别复制它们。首先,我希望有15个FIAT行,然后是10个SEAT行,然后是15个MINI行,然后是10个VOLVO行)。我已经提取了4个唯一值,并试图为这4个值创建一个循环
我尝试了以下代码
for i=1 to 4 car=Sheets("cars").Cells(55,i) With Sheets("cars")
With .Range("A2:X52")
.AutoFilter Field:=1, Criteria1:="car"
.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("results").Cells(freerow, 2)
End With End With
如果有人能提出一个提示,我将不胜感激,提前谢谢
答案 0 :(得分:0)
这似乎执行转移。
Sub moveCars()
Dim i As Long, cars As Variant
cars = Array("fiat", "seat", "mini", "volvo")
With Worksheets("cars")
With .Range("A2:X52")
For i = LBound(cars) To UBound(cars)
.AutoFilter Field:=1, Criteria1:=cars(i)
.SpecialCells(xlCellTypeVisible).Copy _
Destination:=Worksheets("results").Cells(.Rows.Count, 2).End(xlUp).Offset(1, 0)
Next i
End With
End With
End Sub
看到你如何移动15,然后是10,然后是15,那么10不会自定义排序顺序更适合50个单元格(A2:X52)?