Color Filtered Range

MARKG

Board Regular
Joined
Jul 3, 2002
Messages
56
Hello;

I have an autofilter on more than 10 columns of data. I don't have any problems writing code to filter different scenarios. My problem is figuring out what code will filter the data and only color the "result" data up to the last row of the result?

To get by, I have a haphazard macro setup that will filter data and color a set range. I did this to test my "sort by color" and that now works. However, the data will constantly fluctuate therefore my row count will never be the same and I'm left with a lot of blank rows that are colored. Thank-you for your assistance.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
This macro works, it gives the last used (And visible) row of column A. You can adjust it to suit your needs.

<pre>Sub Test()
MsgBox Range("A65536").End(xlUp).Row
End Sub</pre>
 
Upvote 0
Thank-you for the MsgBox - but that doesn't suit my needs. I probably didn't explain it clearly.

Here is my current code:
Selection.AutoFilter
ActiveWindow.LargeScroll ToRight:=-1
Selection.AutoFilter Field:=10, Criteria1:="<>*---*", Operator:=xlAnd
Selection.AutoFilter Field:=9, Criteria1:="~*---~*"
Rows("2:237").Select
With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With

I wan't to eliminate the [Rows("2:237").Select]line as I will never know how many rows appear as a result of the filter. I'm trying to figure out some code that will take just the "result" rows and color them as indicated above. The msgbox actually counted all hidden rows. For instance my "result" rows were 4 but the actual hidden rows were 85, and your msgbox gave the result of 85 - which is not what I needed. Thank-you for your efforts, though.
 
Upvote 0
Actually no. The MsgBox should give you the last visible row after you make the Autofilter. I posted that only as an example of how you can get the last visible row, and then, you could create using a combination of Cells and Range the "resulting" range only. Another option is to use the SpecialCells method, having it to work with Visible cells only.
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,447
Members
448,898
Latest member
drewmorgan128

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