我想创建一个过滤,删除和删除的宏。对价值进行排序 让我们有4列:
- 序列号
- 数据
- 金额
- ID(数字)
醇>
宏应该
无法继续创作。非常感谢帮助!
答案 0 :(得分:1)
这似乎是一个基本问题,它似乎不需要通用解决方案,而是需要2个循环然后作为排序调用...尝试循环(for或while)记录以删除行,例如:
Sub macro1()
ColumnWithSerial = 1
ColumnWithID = 4
ColumnWithAmounts = 3
'loop over column with IDs
Dim i As Long, tempID As Long
i = 3 'variable to loop = set to 1st row with data (after header)
tempID = 1 'variable to update IDs
Do While Len(Sheets("Sheet1").Cells(i, ColumnWithID).Value) > 0
Sheets("Sheet1").Cells(i, ColumnWithSerial).Value = tempID
If Sheets("Sheet1").Cells(i, ColumnWithAmounts).Value = 0 Then
Sheets("Sheet1").Cells(i, ColumnWithAmounts).EntireRow.Delete
Else
tempID = tempID + 1
End If
i = i + 1
Loop
'now call sort method (easy to record and then adapt) (make sure to use sort and not filter)
End Sub
这通常应该完成这项工作,除非有一些参数需要指定......