Highlite filtered items

H

Hugh

Howdy,
Have a worksheet for entry, with a macro that copies filtered ranges to
another sheet.

Is there any way to have code to highlite only the cells in the pasted
range that contain the filter criteria?

Example: filter on Column C, 4 rows copied to sheet 2, highlight the 4
cells in Sheet 2, Column C that contain the filter criteria.
Multiple sets get copied, based on different columns being filtered.

Any help is greatly appreciated.
 
T

Tom Ogilvy

Sub Abd()
Dim f As Filter
Dim rng As Range ' Autofilter range
Dim rng1 As Range ' Visible cells of col 1
Dim rng2 As Range ' destination
Dim rng4 As Range ' Data only in autofilter rng
Set rng = ActiveSheet.AutoFilter.Range
Set rng4 = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
Set rng1 = rng.Columns(1).SpecialCells(xlVisible)
If rng1.Count > 1 Then
With Worksheets("Sheet3")
Set rng2 = .Cells(Rows.Count, 1).End(xlUp)(3)
Set rng2 = rng2.Resize(rng1.Count - 1, _
rng.Columns.Count)
End With
rng4.Copy Destination:=rng2(1)
i = 0
For Each f In ActiveSheet.AutoFilter.Filters
i = i + 1
If f.On Then
rng2.Columns(i).Interior.ColorIndex = 6
End If
Next
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top