PDA

View Full Version : Solved: How do we test for a filtered row in vba



peacenik
11-01-2006, 05:54 PM
I do a lot of work with filters and would like to run macros where I highlight something I have filtered and run a "for each" loop against each cell in the highlighted area. This works well except that when some rows are hidden by the filter and they are included in the range, then the macro is applied to them as well. Does anyone have any ideas about how I can test for this. Here is a sample code that I use.

Sub calcrange()
TargetRange = Selection.Address

For Each cell In Range(TargetRange)
cell.Calculate
Next
End Sub

acw
11-01-2006, 07:15 PM
Hi

how about


Sub calcrange()
set TargetRange = Selection.SpecialCells(xlCellTypeVisible)

For Each ce In TargetRange
cell.Calculate
Next TargetRange
End Sub



Tony

peacenik
11-01-2006, 07:47 PM
Thanks, that was perfect. Will save me minutes!!! but often.