AutoFill visible cells in filtered rows

ysk

New Member
Joined
Nov 26, 2021
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have followed several examples found here on the usage of SpecialCells(xlCellTypeVisible) to autofill visible cells in filtered rows.
However it keeps throwing back Run-time error '1004': AutoFill method of Range class failed.

The last row of code works without the SpecialCells and will autofill all cells including hidden ones. Please help :(


Dim LastRow As Long

'Get last row of data
LastRow = Range("B" & Rows.Count).End(xlUp).Row

ActiveCell.FormulaR1C1 = _
"=VLOOKUP(C[-10],'[Arista ItemsinBacklog - Template.xlsm]JSGBacklog'!C2:C16,15,0)"

Selection.AutoFill Destination:=Range(ActiveCell.Address & ":L" & LastRow).SpecialCells(xlCellTypeVisible)
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
ActiveCell.FormulaR1C1 = _
"=VLOOKUP(C[-10],'[Arista ItemsinBacklog - Template.xlsm]JSGBacklog'!C2:C16,15,0)"

Welcome to the MrExcel board!

The above formula is not a valid formula. Did you mean this?
"=VLOOKUP(RC[-10],'[Arista ItemsinBacklog - Template.xlsm]JSGBacklog'!C2:C16,15,0)"

If so, try it this way instead of using AutoFill

VBA Code:
ActiveCell.Resize(LastRow - ActiveCell.Row + 1).SpecialCells(xlVisible).FormulaR1C1 = _
    "=VLOOKUP(RC[-10],'[Arista ItemsinBacklog - Template.xlsm]JSGBacklog'!C2:C16,15,0)"
 
Upvote 0
Solution
That works!! You are awesome Peter!!

May I know why AutoFill does not work here?
 
Upvote 0
You're welcome. Thanks for the follow-up. :)



Because AutoFill is designed to fill a continuous range of cells, not disjoint ranges as you get when a range is filtered.

Sorry I meant using AutoFill together with SpecialCells(xlCellTypeVisible) for filtered rows. It works for several examples I found in this forum.
 
Upvote 0
Sorry I meant using AutoFill together with SpecialCells(xlCellTypeVisible) for filtered rows.
Yes, I knew you meant that. Still, the visible cells will generally not be one continuous range, but a series of disjoint ranges.

It works for several examples I found in this forum.
Can you point us to one of those so we know what you are referring to?
 
Upvote 0
Yes, I knew you meant that. Still, the visible cells will generally not be one continuous range, but a series of disjoint ranges.


Can you point us to one of those so we know what you are referring to?


Now looking back I may have incorrectly assumed the solutions provided is part of AutoFill method
 
Upvote 0
Now looking back I may have incorrectly assumed the solutions provided is part of AutoFill method
Yes, those threads did not use AutoFill despite the thread titles and in fact used the same structure that I did - particularly that first link. :)
 
Upvote 0
Yes, those threads did not use AutoFill despite the thread titles and in fact used the same structure that I did - particularly that first link. :)

Understood perfectly, thank you so much for your help!
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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