Highlighting Rows when different cell criteria falls into a specified range

CMexcel

New Member
Joined
Jun 2, 2015
Messages
4
I am new to VBA (as in I started today) but have some experience with Matlab. I used excel formulas to create a box that when a length, height, and depth are imputed, ranges are created for each by adding plus and minus .25, or whatever you want. I have a table below it also with a column for lengths, widths and heights. I am trying to make it so the values in these rows will height up when all 3 (length, width, and height) fall into the ranges created described earlier. I really have been struggling but I will post my butchered code anyways. Also, how do I enter down a line in the If statement without an error? Using an underscore didn't seem to work for some reason.

Code:
Private Sub CommandButton2_Click()

Dim i As Long
For i = 10 To 50
If Range("a.i").Value >= Range("H4").Value And Range("a.i").Value <= Range("H4").Value And Range("b.i").Value >= Range("J4").Value And Range("b.i").Value <= Range("K4").Value And Range("c.i").Value >= Range("L4").Value And Range("c.i").Value <= Range("M4").Value Then cell.EntireRow.Interior.ColorIndex = 7
Next i

End Sub
[code]

Thank you greatly
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi,


Welcome to the board.


Your code is below with all the syntax corrected but I thin you've gotten yourself a bit mixed up. See the bold line in the code. It's over complicated because you could simply say

Code:
If Range("A" & i).Value = Range("H4").Value

However this may get you going in the right direction.

Code:
Private Sub CommandButton2_Click()
 Dim i As Long
 For i = 10 To 50
[B] If Range("A" & i).Value >= Range("H4").Value And Range("A" & i).Value <= Range("H4").Value [/B]And _
 Range("B" & i).Value >= Range("J4").Value And Range("B" & i).Value <= Range("K4").Value And _
 Range("C" & i).Value >= Range("L4").Value And Range("C" & i).Value <= Range("M4").Value Then
 Rows(i).EntireRow.Interior.ColorIndex = 7
 End If
 Next i
 End Sub
 
Upvote 0
Could someone help me on the proper syntax for the following line of code? I am trying to instead of using the entirerow highlight, stop it at column t.


For i=10 To 50
...
Range("A:T" & i).Interior.ColorIndex = 6
...


I know that the "A:T" is incorrect, I just don't know how to properly write it.

Also, how do I do code boxes on this forum?

Thanks!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,234
Members
448,951
Latest member
jennlynn

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