如何在if ... else语句中添加循环?

时间:2019-07-24 10:34:24

标签: excel vba

我想逐行检查If ws_Tool.Range("D" & 3).Valuews_Input.Range("S" & I).Value是否相等,但是我的代码只检查了其中一个,剩下的全部保留了

enter code here
Sub match_columns_a()
Dim total, fRow, x As Integer
Dim found As Range
Dim wb_Tool As Workbook
Dim ws_Input As Worksheet
Dim ws_Tool As Worksheet
Dim ws_DiffRep As Worksheet

Set wb_Tool = ActiveWorkbook 

Set ws_Input = wb_Tool.Worksheets("wb1")
Set ws_Tool = wb_Tool.Worksheets("wb2")
Set ws_DiffRep = wb_Tool.Worksheets("wb3")

total = ws_Input.Range("A" & Rows.Count).End(xlUp).Row

For I = 8 To total
    answer1 = ws_Input.Range("A" & I).Value
    Set found = ws_DiffRep.Columns("G:G").Find(what:=answer1) 

    If Not found Is Nothing Then
        If ws_Tool.Range("D" & 3).Value <> ws_Input.Range("S" & I).Value Then
            fRow = (I - 6) - x
            ws_DiffRep.Range("J" & fRow).Value = ws_Input.Range("S" & I).Value
        End If
    End If
Next I

match_columns_b
End Sub

输出应检查上述列的每个单元格,但只检查一个,然后不加任何条件地将其他值相加

0 个答案:

没有答案