Loop to test range of cells

Jason Campbell

Board Regular
Joined
Mar 22, 2016
Messages
77
I am in the need of some assistance!

I need to evaluate all the cells that contain dates in column R, to the end of the range….however, I can expect that there will be dates missing, where the end users hasn’t input an ‘Agreed CR Due Date’. I have accounted for the empty cells in the if statements however, I need to construct a loop that will locate the last entry in column R, to make note of that cell reference and then proceed in checking cell by cell from column R4 down to the last column R entry cell reference already established.

Basically, I need to figure out the loop that I can encase my IF statements within… Based on the results of the IF statements, column T will be populated accordingly.

Below is an example spreadsheet layout and below it the code that have constructed so far, minus the loop part, which I can’t figure out… bit of a newbie!

Assistance will be kindly received! :)
PQRST
3Response to CIRAgreed CR Due DateCR Due DateCR Sent DateCRTime
4CIR Bypassed!N/A10-Mar-17X
5WithdrawnWithdrawn at CIRWdrwn@CIR
6CCN - Await Confirmation NoticeCCNCCN
7Proceed CR Development - Due date agreedInput Agreed Date!
8Proceed CR Development - Due date NOT agreedDate Not Agreed!02-Jun-17

<tbody>
</tbody>


Code:
Range("R4").Activate
 
For
   
        If ActiveCell.Value = "Withdrawn at CIR" Or ActiveCell.Value = "CCN" Or ActiveCell.Value = "" Then
            ActiveCell.Offset(1, 0).Activate
        ElseIf ActiveCell.Offset(0, 1).Value = "" And Date <= ActiveCell.Offset(0, 0).Value Then
            ActiveCell.Offset(0, 2).Value = "CR to be sent?"
            ActiveCell.Offset(1, 0).Activate
        ElseIf ActiveCell.Offset(0, 1).Value = "" And Date > ActiveCell.Offset(0, 0).Value Then
            ActiveCell.Offset(0, 2).Value = "X"
            ActiveCell.Offset(1, 0).Activate
        ElseIf ActiveCell.Offset(0, 1).Value <= ActiveCell.Offset(0, 0).Value Then
            ActiveCell.Offset(0, 2).Value = "OK"
            ActiveCell.Offset(1, 0).Activate
        ElseIf ActiveCell.Offset(0, 1).Value > ActiveCell.Offset(0, 0).Value Then
            ActiveCell.Offset(0, 2).Value = "X"
            ActiveCell.Offset(1, 0).Activate
        End If
 
Next
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I've figured it out! Whoop, Whoop!

I have had to refer to Column P, which would be consistent with data input from the top of the range to the last entry...referring to the count of rows derived from that column, I've then used that with the FOR loop to test each cell in the R Column until at the last entry on the sheet...the if statements have then done their job and populated column T appropriately.

Without Google and the help on this forum...I would be stuffed! Hopefully it will all start to become second nature!

Code:
Dim SH as Worksheet 
Dim CC as Long ' CC refers to 'Cell Check'
Set SH = Thisworkbook.Activesheet 

Range("R4").Activate

CC = SH.Range("P4", SH.Range("P4").End(xlDown)).Rows.Count

For i = 1 To CC
    
        If ActiveCell.Value = "Withdrawn at CIR" Or ActiveCell.Value = "CCN" Or ActiveCell.Value = "" Then
            ActiveCell.Offset(1, 0).Activate
        ElseIf ActiveCell.Offset(0, 1).Value = "" And Date <= ActiveCell.Offset(0, 0).Value Then
            ActiveCell.Offset(0, 2).Value = "CR to be sent?"
            ActiveCell.Offset(1, 0).Activate
        ElseIf ActiveCell.Offset(0, 1).Value = "" And Date > ActiveCell.Offset(0, 0).Value Then
            ActiveCell.Offset(0, 2).Value = "X"
            ActiveCell.Offset(1, 0).Activate
        ElseIf ActiveCell.Offset(0, 1).Value <= ActiveCell.Offset(0, 0).Value Then
            ActiveCell.Offset(0, 2).Value = "OK"
            ActiveCell.Offset(1, 0).Activate
        ElseIf ActiveCell.Offset(0, 1).Value > ActiveCell.Offset(0, 0).Value Then
            ActiveCell.Offset(0, 2).Value = "X"
            ActiveCell.Offset(1, 0).Activate
        End If
Next
 
Upvote 0

Forum statistics

Threads
1,217,386
Messages
6,136,279
Members
450,001
Latest member
KWeekley08

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