Problems looping through the sheet

dfwconsumables

New Member
Joined
Sep 21, 2017
Messages
4
I have a worksheet, there is currently 14 columns with information in them, only 6 of the columns are important. There are currently 3,500 rows in the workbook. I have created a macro that loops through column E and highlights the range C:N for any value greater than 1. That value is in a summed row in Column E (like a pivot table). Call that summed amount the variable i, I would like to offset the row up, so a negative i and then highlight columns C:N. I have tried 10 differing ways, but I just can't get my code code to work. My code snippet is below, please help with any comments, I'm new to this so please be gentle.

Sub VerificationLine()
Dim i As Long, r1 As Range, r2 As Range
FinalRow = Cells(Rows.Count, 3).End(xlUp).Row


For i = 3 To FinalRow
Set r1 = Range("e" & i)
Set r2 = Range("C" & i & ":N" & i)
If r1.Value = 1 Then r2.Interior.Color = xlNone
If r1.Value > 1 Then r2.Interior.Color = vbYellow
Next i
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
So if E5 was greater than 1 you would want to highlight C4:N4?

If that's right try this.
Code:
Sub VerificationLine()
Dim i As Long, r1 As Range, r2 As Range

    FinalRow = Cells(Rows.Count, 3).End(xlUp).Row

    For i = 3 To FinalRow
        Set r1 = Range("e" & i)
        Set r2 = Range("C" & i - 1 & ":N" & i - 1)
        If r1.Value = 1 Then r2.Interior.Color = xlNone
        If r1.Value > 1 Then r2.Interior.Color = vbYellow
    Next i
    
End Sub
 
Upvote 0
Sorry. I didn't see Norie's response.
 
Last edited:
Upvote 0
That is almost correct. I want C through N10 to highlighted but more importantly, I want the total in E10, to offset the rows to highlight so that row 9, 8, and 7 are highlighted as well
 
Upvote 0
Do you mean the value in E10 determines the no of rows above to highlight?
 
Upvote 0
Do you mean the value in E10 determines the no of rows above to highlight?

That is right, the value in E10 (which is the first item with a value greater than one) would be the amount of rows to move through, and that is move up through.
 
Upvote 0

Forum statistics

Threads
1,215,717
Messages
6,126,422
Members
449,314
Latest member
MrSabo83

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