Multiple ranges of cells with checking values and entering text

stillwater32

New Member
Joined
Nov 4, 2015
Messages
5
Hi! I have set B of numbers in range of B1 to B142. I have set C of numbers in range C2 to C142. I have a set F of numbers in range F3 to F142. I have a set M of numbers from H2 to BS2. I need something to check that if (cell in M = cell in B) AND if (cell in F = cell in C) then enter "Yes" in the row from F and column from M where the condition was met. For example, lets say B20 = 100, X2 = 100, C7 = 25, and F41 = 25 then cell X41 = "Yes". Please note, some cells in F are blank. Besides that all cells contain numbers. If you need any more clarification, please ask. Thank you very much!
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Bump!

Here is my attempt but it is not working. When it goes inside the second IF I don't think it works there. Any ideas?

Code:
Private Sub CommandButton21_Click()
Dim ThisCell1 As Range
Dim ThisCell2 As Range
Dim ThisCell3 As Range
Dim ThisCell4 As Range
    For Each ThisCell1 In Range("C2:C142")
    'This is the range of cells to check
        For Each ThisCell2 In Range("F3:F141")
        'This is the range of cells to compare
            If ThisCell1.Value = ThisCell2.Value Then
                For Each ThisCell3 In Range("B2:B142")
                    For Each ThisCell4 In Range("H2:BS2")
                        If ThisCell3.Value = ThisCell4.Value Then
                            MyRow = ThisCell2.Row
                            MyCol = ThisCell4.Column
                            ActiveSheet.Cells(MyRow, MyCol).Value = "Yes"
                        Exit For
                        End If
                    Next ThisCell4
                    Next ThisCell3
                Exit For
                End If
        Next ThisCell2
        Next ThisCell1
End Sub
 
Upvote 0
Here is the solution for anyone interested.

Code:
Private Sub CommandButton21_Click()
Dim ThisCell1 As Range
Dim ThisCell2 As Range
Dim ThisCell3 As Range
Dim ThisCell4 As Range


    For Each ThisCell1 In Range("C2:C142")
    'This is the range of cells to check
        For Each ThisCell2 In Range("F3:F141")
        'This is the range of cells to compare
            If ThisCell1.Value = ThisCell2.Value Then
                    Set ThisCell3 = Cells(ThisCell1.Row, 2)
                    ' If C == F then loop through M and compare to the value in Column B, row of current C
                    For Each ThisCell4 In Range("H2:BS2")
                        If ThisCell3.Value = ThisCell4.Value Then
                            ' Row of ThisCell2 and Column of ThisCell4
                            Cells(ThisCell2.Row, ThisCell4.Column).Value = "Yes"
                            Exit For
                        End If
                    Next ThisCell4
                Exit For
            End If
        Next ThisCell2
    Next ThisCell1
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,115
Messages
6,128,915
Members
449,478
Latest member
Davenil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top