How to return true if two Range objects have the same range in a for loop?

anewuser111

New Member
Joined
Jan 5, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
0
I am new to VBA. I'm writing a program where a macro scans the worksheet, each row is an application. The last column CR writes if the applicant is eligible or not based on some criteria.
I am trying to write a loop that goes through each applicant and checks for completeness. For one condition, it is "If the loop is on the cell that says Yes/No for funding (AT), and value of the cell is Yes, and the cell next to it is empty, then return for the final column (CR) that application is incomplete.
I have tried to implement that below but for some reason I am still getting complete when testing even when the applicant should be incomplete.
What is wrong with my code? Is it because the cells are comparing the values and not the ranges?
VBA Code:
For Each c In Range("B2:CI10").Cells

completeness = "CR" & c.row
Set completeness2 = Range(completeness)

fundingCell = "AT" & c.row
Set fundingCell2 = Range(fundingCell)


If (c = fundingCell And fundingCell2.Value = "Yes" And IsEmpty(c.Offset(0, 1))) Then

completeness2 = "incomplete"


Else

completeness2 = "Complete"


End If


Next


End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Which cells should be compared?

For the first row with the way that you have written the code, it is comparing B2 to C2, C2 to D2, etc. The result that is shown in the cell change after each pair is checked so what you see in the cell will be comparing CI2 (as c) to CJ2 (c.offset(0, 1)) which could explain the strange results.
 
Upvote 0

Forum statistics

Threads
1,215,852
Messages
6,127,313
Members
449,374
Latest member
analystvar

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