比较一个单元格对一行,然后input数据到另一个单元格,如果有匹配

我试图找出一种方法来比较Sheet2中的一个单元格与Sheet1中的整个行。 如果有匹配,那么我想用“X”标记一个请求的行。 标记“X”的行需要改变,因为我正在比较众多的用户,我想我可以设置一个stringinput。 一旦单个单元格检查了整行,我需要列中的下一个单元格检查整行,并相应地标记“X”。

最重要的是我正在一个软件数据库安装在50台计算机,我有一个所有可能的应用程序和所有安装的应用程序的列表,每台计算机。 并不是每台计算机都有各自的应用程序,所以我试图自动化一个电子表格,根据收集的数据标记哪台计算机上有哪些软件。 如果这没有意义,请让我知道。 我经常理解Powershell中的逻辑stream程和程序,但是我对VBA命令不太熟悉。 谢谢!

编辑:添加图片的解释。

编辑2:添加下面的代码,我有。 似乎运行检查,但c.Value总是错的。 它只是不完全检查。 我testing了CellApp.Select以确认我想要的范围是正确的。 循环只是不检查正确的值,我不认为。 对于示例图片,假设“机器3的程序列表”位于Sheet2上,并从A1开始。

例

Option Explicit Sub check() Dim wsApplications As Worksheet, wsMachines As Worksheet Dim CellApp As Range, CellMachine As Range Dim listStRow As Long, listEndRow As Long, listCol As Long Dim c As Range Dim Counter As Integer Set wsApplications = Sheets("Sheet2") Set wsMachines = Sheets("Sheet1") Counter = 3 'data start(row, col)on machines-list sheet listStRow = 2 listCol = 1 With wsApplications 'find last machine in list listEndRow = .Cells(Rows.Count, listCol).End(xlUp).Row 'Set CellApp Range Set CellApp = Range("A2", Cells(listEndRow, 1)) For Each c In CellApp.Cells 'For each cell in the CellApp Range... Set CellMachine = Cells(1, Counter) Counter = Counter + 1 'Defines CellMachines as Cell "1,3" then "1,4" then "1,5" etc... If c.Value = CellMachine.Value Then 'If the cell in CellApp is equal to the cell that is currently CellMachine wsMachines.Cells(4, CellMachine.Column).Value = "X" 'Mark an X underneath the column that matches up. Designated Row 4 for a test. End If Next c End With 

一种方法概述如下。 这假定mc /程序数据按照下面的图像呈现,并且您的“matrix”按照您的Q表示。调整代码中的表格名称和数据位置以适应。

在这里输入图像说明

 Option Explicit Sub check() Dim wsList As Worksheet, wsMatrix As Worksheet Dim r As Range, c As Range Dim listStRow As Long, listEndRow As Long, listCol As Long, n As Long Dim matHdr As Long, matCol As Long Dim mcNo As String, progNo As String Set wsList = Sheets("Sheet2") Set wsMatrix = Sheets("Sheet1") 'data start(row, col)on machines-list sheet listStRow = 2 listCol = 1 'start position of matrix (row, col) to be filled matHdr = 1 matCol = 1 With wsList 'find last machine in list listEndRow = .Cells(Rows.Count, listCol).End(xlUp).Row 'for each mc in list For n = listStRow To listEndRow 'construct matrix intersect 'headers' for mc and program mcNo = "Machine " & CStr(.Cells(n, listCol).Value) progNo = "Program " & CStr(.Cells(n, listCol).Offset(0, 1).Value) 'populate matrix with "X" With wsMatrix Set r = .Columns(matCol).Find(mcNo, , , xlWhole) If Not r Is Nothing Then Set c = .Rows(matHdr).Find(progNo, , , xlWhole) If Not c Is Nothing Then Intersect(r.EntireRow, c.EntireColumn) = "X" End If End If End With Next n End With End Sub