Question : remove formula from hidden rows

I have the following code that applies the formula to the cells in the range, the problem that I ahve noticed is that I have 2 hidden rows and it also applies the formulas to these as well.

How can apply the formula to the range but skip the hidden rows
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Set rng4 = Range([j7], [j7].End(xlDown))

    '   Set Link Start
'sht.Range("a7").Value = 1
'''Set rng1 = Range([q2], [q2].End(xlDown))
'''
'''Set rng2 = Range([p2], Cells([q1].Value * 7 + 1, 16))
'Set rng2 = Range("q2:q" & ActiveSheet.Range("q" & ActiveSheet.Rows.Count).End(xlUp).Row).Resize(, 7)
'Debug.Print rng2.Address

'   Apply Formula

rng4.Offset(0, -9).FormulaR1C1 = "=IF(R[-3]C="""",1,SUM(R[-3]C)+1)"

Answer : remove formula from hidden rows

You can used the SpecialCells(xlCellTypeVisible) property to acheive this...

Change your last line to...

rng4.range.SpecialCells(xlCellTypeVisible).Offset(0, -9).FormulaR1C1 = "=IF(R[-3]C="""",1,SUM(R[-3]C)+1)"



OR, your first line to...

Set rng4 = Range([j7], [j7].End(xlDown)).SpecialCells(xlCellTypeVisible)
Random Solutions  
 
programming4us programming4us