在工作表之间传输数据并在Excel中过滤出重复项
Sheet1= master field that I am trying to copy the content from the other sheets Sheet2= Distributor1 Column A has UPC Column B Price Column C Shipping Price Sheet3= Distributor2 Column A has UPC Column B Price Column C Shipping Price
在工作表1中,我想粘贴/复制所有UPC之间的工作表2和工作表3.如果有一个重复的(比较UPC),我想两个较小的转移过来(less了两个B列价格不担心航运)。
我一直在尝试这一整天,无法得到它。 试图将所有UPC复制到工作表1从两张表标记重复我只是不能得到它的工作,所以我没有重复的产品。 任何想法是更简单的方法和可能的解决scheme?
给这个代码一个镜头。 它应该做你需要的。
Sub RemoveDuplicateUPCsAndKeepLowestPrice() Application.ScreenUpdating = False Dim Sht1 As Integer Dim Sht2 As Integer Dim Sht3 As Integer Sht2 = WorksheetFunction.CountA(Sheets("Sheet2").Range("A:A")) Sht3 = WorksheetFunction.CountA(Sheets("Sheet3").Range("A:A")) Sheets("Sheet1").Range("A:C").ClearContents Sheets("Sheet1").Range("A1:A" & Sht2 + Sht3).NumberFormat = "@" Sheets("Sheet1").Range("A1:C" & Sht2).Value = Sheets("Sheet2").Range("A1:C" & Sht2).Value Sheets("Sheet1").Range("A" & Sht2 + 1 & ":C" & (Sht3 + Sht2 - 1)).Value = Sheets("Sheet3").Range("A2:C" & Sht3).Value Sheets("Sheet1").Sort.SortFields.Clear Sheets("Sheet1").Sort.SortFields.Add Key:=Range("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal Sheets("Sheet1").Sort.SortFields.Add Key:=Range("B:B"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal With Sheets("Sheet1").Sort .SetRange Range("A:C") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Sheets("Sheet1").Range("A:C").RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes Sht1 = WorksheetFunction.CountA(Sheets("Sheet1").Range("A:A")) For i = 1 To Sht1 If Sheets("Sheet1").Range("A" & i).Value = Sheets("Sheet1").Range("A" & (i + 1)).Value Then Sheets("Sheet1").Range("A" & i & ":C" & i).ClearContents End If Next i Sheets("Sheet1").Sort.SortFields.Clear Sheets("Sheet1").Sort.SortFields.Add Key:=Range("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal Sheets("Sheet1").Sort.SortFields.Add Key:=Range("B:B"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal With Sheets("Sheet1").Sort .SetRange Range("A:C") .Header = xlYes .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Application.ScreenUpdating = True End Sub