VBAmacrosExcel用于分组,查找和删除重复项

我不知道该怎么做,所以我在这里问。
所以这是我在Excel中的CSV:

在这里输入图像描述

正如你所看到的,我们在CSV和价格都有dusplicates。
价格必须大小。 你可以看到,大小是“相同”,但他们有空间。

我需要什么?

VBA需要对每个sku进行分组,例如:

在这里输入图像描述

在此之后,它需要find重复的价格,并select这些行,删除重复,而不是默认的,例如:

在这里输入图像说明

下一个SKU组:

在这里输入图像说明
至less,我认为这是做这个的程序,如果还有其他的方法,我想听听。

对我来说,我不知道该怎么做。 也许是一个Excel函数?
这甚至有可能吗?

更新1

所以我尝试了R3uK的解决scheme和Marco Getrost的解决scheme,R3uK对我来说是最好的。

我已经改变了他的VBA喜欢我的大CSV。
这里是:

Sub test_Sj03rs() With ActiveSheet 'In column D With .Range("Y:Y") 'Change all double spaces to single ones (being extra careful) .Replace What:=" ", _ Replacement:=" ", _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ MatchCase:=False, _ SearchFormat:=False, _ ReplaceFormat:=False 'Change all slashes+spaces to single slash .Replace What:="/ ", _ Replacement:="/", _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ MatchCase:=False, _ SearchFormat:=False, _ ReplaceFormat:=False 'Change all spaces+slashes to single slash .Replace What:=" /", _ Replacement:="/", _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ MatchCase:=False, _ SearchFormat:=False, _ ReplaceFormat:=False End With With .Range("A:AA") 'To get rid of formulas if there is .Value = .Value 'Remove duplicates considering all columns .RemoveDuplicates _ Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27), _ Header:=xlYes End With End With End Sub 

这是它应该用于的文件。 请记住,这个文件大约是13.000行。

在这里输入图像描述

更新2

这是CSV,供想要testing的人使用。

CSV

我假设你实际上使用你的例子中描述的设置。 否则,你会想对代码进行一些更改。

 Sub test() Dim rN& With ActiveSheet .Columns("D").Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:= _ xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False rN = 1 Do While .Cells(rN, 1).Value <> "" Do While (.Cells(rN, 1).Value = .Cells(rN + 1, 1).Value And .Cells(rN, 4).Value = .Cells(rN + 1, 4).Value _ And .Cells(rN, 2).Value = .Cells(rN + 1, 2).Value And .Cells(rN, 3).Value = .Cells(rN + 1, 3).Value) .Cells(rN + 1, 1).EntireRow.Delete Loop rN = rN + 1 Loop End With End Sub 

这应该做的伎俩:

 Sub test_Sj03rs() Dim r as Range With ActiveSheet 'In column U (QTY) For Each r in .Range("Y:Y").Cells r.Value = r.Value * 1 Next r 'In column Y With .Range("Y:Y") 'Change all double spaces to single ones (being extra careful) .Replace What:=" ", _ Replacement:=" ", _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ MatchCase:=False, _ SearchFormat:=False, _ ReplaceFormat:=False 'Change all slashes+spaces to single slash .Replace What:="/ ", _ Replacement:="/", _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ MatchCase:=False, _ SearchFormat:=False, _ ReplaceFormat:=False 'Change all spaces+slashes to single slash .Replace What:=" /", _ Replacement:="/", _ LookAt:=xlPart, _ SearchOrder:=xlByRows, _ MatchCase:=False, _ SearchFormat:=False, _ ReplaceFormat:=False End With With .Range("A:AA") 'To get rid of formulas if there is .Value = .Value 'Remove duplicates considering all columns .RemoveDuplicates _ Columns:=Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27), _ Header:=xlYes End With End With End Sub 

可怕的我知道,但如果你没有那么多的数据,这应该工作。

 Sub remove() Dim lRowNo As Long Dim lCheckRow As Long Dim sString As String Dim sCheckString As String For lRowNo = 2 To ActiveSheet.UsedRange.Rows.Count sString = Replace(Cells(lRowNo, 4), " ", "") For lCheckRow = 2 To lRowNo - 1 sCheckString = Replace(Cells(lCheckRow, 4), " ", "") If sString = sCheckString Then Rows(lRowNo).EntireRow.Delete lRowNo = lRowNo -1 exit for End If Next lCheckRow Next lRowNo End Sub