今天,我在尝试替换点 (.) 时遇到了此代码,但前提是 sheet1 的列表中的值与另一个工作表的另一个列表中的一个值不匹配(同一工作簿)。“ Argument NOT optional ” 是错误,但它不会给我任何其他提示。
Sub Filter(wsS As Worksheet, wsN As Worksheet, i As Integer, j As Integer, k As Integer, l As Integer, a As Integer)
'
' substitute Macro
'
Application.ScreenUpdating = False
Range("a1").FormulaR1C1 = "Sorted"
Set wsS = Sheets("sheet1")
Set wsN = Sheets("non_confid")
col1 = "A"
col2 = "E"
col3 = "C"
For a = 1 To 200
If wsS.Range(col1 & a) = wsN.Range("AB2:ab600") Then
a = a + 1
Else: Range(col1 & a).Replace What:=".", Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
a = a + 1
End If
Next
Range("a1").AutoFilter
ActiveWorkbook.Worksheets("sheet1").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("sheet1").AutoFilter.Sort.SortFields.Add Key:=Range("A:A"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("sheet1").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("a1").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 15773696
.TintAndShade = 0
.PatternTintAndShade = 0
End With
With Selection.Font
.Color = -10477568
.TintAndShade = 0
End With
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1:$a$500"), , xlYes).Name = "Table1"
ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:="<>"
Set wsS = Sheets("sheet1") 'this has assigned the worksheet sheet1 to wsS
Set wsN = Sheets("non_confid") 'this has assigned the worksheet sheet1 to wsU
i = 2
For j = 2 To 300
If Not IsEmpty(wsS.Range(col1 & j).Value) Then
wsS.Range(col3 & i - 1).Value = wsS.Range(col1 & j).Value
i = i + 1
End If
Next
Range("A:B").EntireColumn.Delete
For k = 1 To 300
If IsEmpty(wsS.Range(col1 & k).Value) Then
i = i + 1 'Exit For 'this jumps out of the loop, so no more copying.
Else
wsN.Range(col2 & i).Value = wsS.Range(col1 & k).Value
i = i + 1
End If
Next
Sheets("non_confid").Select
Columns("A:G").EntireColumn.AutoFit
Range("e1").Select
ActiveSheet.ListObjects("Status").Range.AutoFilter Field:=4, Criteria1:="<>"
Range("A1").Select
ActiveWorkbook.Saved = True
Application.ScreenUpdating = True
End Sub