How to loop through and select a row using VBA and variables

philwojo

Well-known Member
Joined
May 10, 2013
Messages
533
OK, I know this is super easy but I am struggling with it.

I want to do a test to check a cell for a specific value, in this case 3000, I know how to do that and have that part working.

Now once I find that cell with the 3000 value I want to highlight that row from column-B through Column-BF.

This is the part I am struggling with what VBA code do I use to do this, here is what I have now, but it isn't working:

Code:
Range(Cells(rng, lastrow)).Interior.TintAndShade = -0.249977111117893

I know that isn't right, I am just not sure how to change it. "rng" is set to .Range("B7:B6000"), I also have this:
Dim textlen As Integer, rng As Range, Cell As Range, RecordLen As Integer

Thanks for any feedback, I want to learn how to do this but I am just stuck, maybe because it is Friday.
 
Thanks Rick, I will read up on the differences between the two so I can better understand. I know that Column-BF is the same as 57 in Fluff's code though.
No, 57 is the number of cells in the column range B:BF... Resize takes a single cell or range of cells and makes a bigger range out of it where the number of cells downward from the cell or upper left corner of the range of cells is specified by the number in the first argument (if no value is specified as in Fluff's code, the number of cells in the range in that direction remains unchanged) and where the number of cells across to the right from the cell or upper left corner of the range of cells is specified by the number in the second argument (the 57 in Fluff's code). The code I posted (an intersection of a range of full rows with a range of full columns) eliminates you having to count or calculate the number of rows and/or columns to resize which, for a large number of cells in either direction, I think is easier to write code for (and, maybe more importantly, understand what cells are involved if you have to come back to your code in 6 months to revise it).
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,840
Messages
6,121,895
Members
449,058
Latest member
Guy Boot

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