专家,我有一个包含产品名称和价格清单的电子表格。但是产品列包含原始产品的许多重复项。每个产品名称末尾都用+ 1,+ 2 ---- + 30值分隔此重复项。但是这些产品的价格列中包含enter image description here错误的价格。工作表的结构如下。
这是产品和价格的示例。重复产品的价格有误。该产品应类似于原始产品。我正在使用此宏,但它会删除整个行中的重复值。
Option Explicit
Sub DeleteDuplicateValues()
'
' DeleteDuplicateValues Macro
' Delete Duplicate Values with different Criteria
'
Application.ScreenUpdating = False
Range("A1:J1").Select
Selection.AutoFilter
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*1+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*2+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*3+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*4+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*5+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*6+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*7+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*8+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*9+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*10+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*11+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*12+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*13+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*14+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*15+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*16+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*17+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*18+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*19+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*20+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*21+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*22+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*23+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*24+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Columns("C:C").Select
ActiveSheet.Range("$A$1:$J$43000").AutoFilter Field:=3, Criteria1:="=*25+*", _
Operator:=xlAnd
Rows("4:4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Delete Shift:=xlUp
Application.ScreenUpdating = True
ActiveSheet.ShowAllData
MsgBox ("Data Cleaning Succesfully")
End Sub
如何完成不删除该行的操作。但是它应该输入产品的原始价格。
感谢前进。
答案 0 :(得分:0)
这种代码可以达到目的:
Option Explicit
Sub test()
Dim LastRow As Long
LastRow = Range("C" & Rows.Count).End(xlUp).Row
Dim STRcell As String
For i = 1 To LastRow
If Right(Cells(i, 3).Value, 1) = "+" Then
If Left(Right(Cells(i, 3).Value, 3), 1) = " " Then
STRcell = Left(Cells(i, 3).Value, Len(Cells(i, 3).Value) - 3)
Cells(i, 3).Offset(0, 4).Value = Excel.WorksheetFunction.VLookup(STRcell, Range("C:Z"), 5, 0) 'previously Findval(STRcell, Range("C:C"))
ElseIf Left(Right(Cells(i, 3).Value, 4), 1) = " " Then
STRcell = Left(Cells(i, 3).Value, Len(Cells(i, 3).Value) - 4)
Cells(i, 3).Offset(0, 4).Value = Excel.WorksheetFunction.VLookup(STRcell, Range("C:Z"), 5, 0) 'previously Findval(STRcell, Range("C:C"))
End If
End If
Next
End Sub
与此有关的问题是格式是否不同,例如,如果在“ 5+”之前没有空格,或者在+(例如:“ 100+”)之前没有3位数字