How to limit autofill

DBus

New Member
Joined
Mar 6, 2011
Messages
14
I am trying to fill a specific number of filtered cells with the certain value, stored in H1. I found the following code, on the web, which enables me to fill all of the filtered cells, but how can I limit the number of cells, which are filled. If the filtered data extends to ten cells, how can I stop the fill at say the eighth cell?

Dim cell As Range
Dim source As Range
Set source = Range("A2:A20")
For Each cell In source.SpecialCells(xlCellTypeVisible)
If cell <> "" Then
cell.Offset(, 2).Formula = Range("H1")
End If
Next
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top