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! :)
[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]P[/TD]
[TD]Q[/TD]
[TD]R[/TD]
[TD]S[/TD]
[TD]T[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Response to CIR[/TD]
[TD]Agreed CR Due Date[/TD]
[TD]CR Due Date[/TD]
[TD]CR Sent Date[/TD]
[TD]CRTime[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]CIR Bypassed![/TD]
[TD]N/A[/TD]
[TD]10-Mar-17[/TD]
[TD][/TD]
[TD]X[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Withdrawn[/TD]
[TD][/TD]
[TD]Withdrawn at CIR[/TD]
[TD][/TD]
[TD]Wdrwn@CIR[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]CCN - Await Confirmation Notice[/TD]
[TD][/TD]
[TD]CCN[/TD]
[TD][/TD]
[TD]CCN[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Proceed CR Development - Due date agreed[/TD]
[TD]Input Agreed Date![/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Proceed CR Development - Due date NOT agreed[/TD]
[TD]Date Not Agreed![/TD]
[TD]02-Jun-17[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


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,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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