如何在公式后删除空格

时间:2019-02-11 12:32:37

标签: excel vba excel-formula count match

我正在尝试创建一个Match宏,该宏比较两个列表,并为我提供仅出现在一个列表中的单元格。然后将单元格复制到另一个计算单元格的工作表中。但是,空白单元格也正在复制,我不知道为什么。 以下是我所拥有的:

Sub Macro_do_Match()

Dim CopyrangeB As String
Dim lRowB As Integer
Dim fRowB As Integer
Dim CopyrangeD As String
Dim lRowD As Integer
Dim fRowD As Integer
Dim rng As Range

' Defines range for column B

lRowB = Cells(Rows.Count, 1).End(xlUp).Row
fRowB = 2

Let CopyrangeB = "B" & fRowB & ":" & "B" & lRowB

' "macro"

    Range("B2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(NOT(ISERROR(MATCH(C[-1],C[1],0)))=FALSE,C[-1], """")"
    Range("B2").Select
    Selection.AutoFill Destination:=Range(CopyrangeB)

' Defines range for column D

lRowD = Cells(Rows.Count, 3).End(xlUp).Row
fRowD = 2

Let CopyrangeD = "D" & fRowD & ":" & "D" & lRowD

' "macro"

    Range("D2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(NOT(ISERROR(MATCH(C[-1],C[-3],0)))=FALSE,C[-1], """")"
    Range("D2").Select
    Selection.AutoFill Destination:=Range(CopyrangeD)

'Copy and paste B

    Range("B2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Final Results").Select
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

'Copy and paste D

    Sheets("Insert Lists").Select
    Range("D2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Final Results").Select
    Range("B2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False

0 个答案:

没有答案