View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
PatJohnson PatJohnson is offline
external usenet poster
 
Posts: 2
Default Dynamic Autofilter using VBA

Hello,

I'm trying to use vba to color-code cells A through M in the visible rows that are chosen based on an autofilter in column M. I was able to do this using the following code which autofilters for the criteria selected in column M and then it scrolls to the first visible cell in the data that I want to color code(in this case cell A345) and then it highlights the visible data and color codes it.

Not sure, though, how to do it dynamically because each month the total number of rows will change (this month , there were 2607) and also the number for records for the selected criteria will change (in this example, the first record with the criteria = "Replaced" was on row 345, but it could be on row 245 next month).

ActiveSheet.Range("$A$1:$Y$2607").AutoFilter Field:=13, Criteria1:= _
"Replaced"
ActiveWindow.ScrollRow = 2585
ActiveWindow.ScrollRow = 337
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Range("A345:M345").Select
Range(Selection, Selection.End(xlDown)).Select
With Selection.Font
.ThemeColor = xlThemeColorDark2
.TintAndShade = -0.499984740745262
End With

Thanks,
Pat