Windows 如何对照另一工作簿中的主列表检查一个工作簿中的原始数据

Windows 如何对照另一工作簿中的主列表检查一个工作簿中的原始数据,windows,excel,vba,Windows,Excel,Vba,我是VBA Excel新手,需要一些帮助。我有一个工作簿,其中包含可接受字符串值的主列表。此工作簿定期更新。我有另一个包含所有原始数据的工作簿。我想让宏打开主列表,对照主列表检查原始数据第二列中的每个条目,并删除主列表中不包含的任何单元格。我需要一些指针来指引我前进。以下是我到目前为止的情况: 次优先检查() 提前感谢您提供的任何帮助。这没有Excel部分,但是像这样的东西怎么样 public class CellValue { public string the

我是VBA Excel新手,需要一些帮助。我有一个工作簿,其中包含可接受字符串值的主列表。此工作簿定期更新。我有另一个包含所有原始数据的工作簿。我想让宏打开主列表,对照主列表检查原始数据第二列中的每个条目,并删除主列表中不包含的任何单元格。我需要一些指针来指引我前进。以下是我到目前为止的情况:

次优先检查()


提前感谢您提供的任何帮助。

这没有Excel部分,但是像这样的东西怎么样

    public class CellValue
    {
        public string theValue { get; set; }
    }

    List<CellValue> masterList = new List<CellValue>(); //Load these values into the list
    List<CellValue> otherList = new List<CellValue>();   //Load these values into the list

    List<string> onesToDelete = otherList.Select(x => !masterList.Any(x2 => x2.theValue == x.theValue));
公共类单元格值
{
公共字符串值{get;set;}
}
列表主列表=新列表()//将这些值加载到列表中
List otherList=新列表()//将这些值加载到列表中
List onesToDelete=otherList.Select(x=>!masterList.Any(x2=>x2.theValue==x.theValue));

这没有Excel部分,但是像这样的东西怎么样

    public class CellValue
    {
        public string theValue { get; set; }
    }

    List<CellValue> masterList = new List<CellValue>(); //Load these values into the list
    List<CellValue> otherList = new List<CellValue>();   //Load these values into the list

    List<string> onesToDelete = otherList.Select(x => !masterList.Any(x2 => x2.theValue == x.theValue));
公共类单元格值
{
公共字符串值{get;set;}
}
列表主列表=新列表()//将这些值加载到列表中
List otherList=新列表()//将这些值加载到列表中
List onesToDelete=otherList.Select(x=>!masterList.Any(x2=>x2.theValue==x.theValue));

在VBA中,您可以尝试以下操作:

Sub Firstcheck()
    Dim cel As Range, masterList
    With Workbooks.Open("T:\Communications and Media\Media\Media    Reporting\media master list.xlsx")
        With .Worksheets(1)
            masterList = .Range(.Range("A1"), .Range("A1").End(xlDown)).value2
        End With
        .Close False
    End With

    For Each cel In ThisWorkbook.Worksheets(1).UsedRange.Columns(2).Cells
        If IsError(Application.match(Trim(cel.value2)), masterList) Then
            cel.Interior.ColorIndex = 4
        Else
            cel.Interior.ColorIndex = 5
        End If
    Next
End Sub

在VBA中,您可以尝试以下操作:

Sub Firstcheck()
    Dim cel As Range, masterList
    With Workbooks.Open("T:\Communications and Media\Media\Media    Reporting\media master list.xlsx")
        With .Worksheets(1)
            masterList = .Range(.Range("A1"), .Range("A1").End(xlDown)).value2
        End With
        .Close False
    End With

    For Each cel In ThisWorkbook.Worksheets(1).UsedRange.Columns(2).Cells
        If IsError(Application.match(Trim(cel.value2)), masterList) Then
            cel.Interior.ColorIndex = 4
        Else
            cel.Interior.ColorIndex = 5
        End If
    Next
End Sub

哇,我一点也不明白。我得去读公共课和公共字符串。谢谢,我一点也不明白。我得去读公共课和公共字符串。Thanks@sirentec我不知道如何使用公共单元格和公共字符串,但我能够编写一个工作程序。唯一的问题是excel在运行时经常冻结。我已经编辑了上面的程序以包含新代码。@sirentec我不知道如何使用公共单元格和公共字符串,但我能够编写一个工作程序。唯一的问题是excel在运行时经常冻结。我已经编辑了上面的程序来包含新的代码。那太完美了。我真的很感激,太完美了。我真的很感激。