View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Damian Carrillo[_2_] Damian Carrillo[_2_] is offline
external usenet poster
 
Posts: 9
Default AutoFilter: Loop Thru Visible Rows?

Rowan,

A very belated thank you for the help! Your method worked so well I have
started using it for setting cell values in all my projects! I was so
excited when I first read the post weeks ago and found that it worked! But I
forgot to respond! My apologies and thanks again!

Damian

"Rowan" wrote:

Damian

I haven't worked my way through all of your code but hopefully this will
help. The following code autofilters data on a sheet, adds two columns (I and
J) and then inserts formulas into the visible cells in columns I and J.

Sub AddFormula()

Dim endRow As Long

Selection.AutoFilter Field:=8, Criteria1:="Y"

Range("I1").EntireColumn.Insert
Range("I1").EntireColumn.Insert

endRow = Cells(Rows.Count, 8).End(xlUp).Row

Range(Cells(2, 9), Cells(endRow, 9)). _
SpecialCells(xlCellTypeVisible).FormulaR1C1 _
= "=IF(RC[-6]20,""My First Formula"","""")"

Range(Cells(2, 10), Cells(endRow, 10)). _
SpecialCells(xlCellTypeVisible).FormulaR1C1 _
= "=IF(RC[-9]20,""My Second Formula"","""")"

End Sub

Regards
Rowan