Autofilling Formulae no filtered cells

hercules89

New Member
Joined
Jan 24, 2019
Messages
3
Hi,
I am working on a spreadsheet to increase efficiency at work but I have ran into a problem...I have filter column F and then inserted a new column I and input a concatenate formula. I then have tried extending this down to all the other filtered cells and then remove the filter. This seems to work fine when doing manually and recording the macro but then doesn’t work when I try running the macro...the two snippets of code I have are below:

This is the vba code I get when recording the macro but when I run it again it only copies cell I1 into cell I2, rather than copying the formula in I2 down to all filtered cells:

Columns("I:I").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("I1").Select
ActiveCell.FormulaR1C1 = "Unique Ref"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-6],RC[-2])"
Range("I2").Select
Selection.FillDown

This code I have played around with and does appear to extend the formula across all filtered cells but when I remove the filter, it has also applied it all cells, filtered and non-filtered:

Columns("I:I").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range("I1").Select
ActiveCell.FormulaR1C1 = "Unique Ref"
Range("I2").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[-6],RC[-2])"
Range("I2").Select
Selection.AutoFill Range(ActiveCell, ActiveCell.Offset(0, -2).End(xlDown).Offset(0, 2))

Can somebody help me with where I am going wrong here?

Thanks,
Herc
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
How about
Code:
Sub hercules89()
   Columns("I:I").Insert
   Range("I1").Value = "Unique Ref"
   Range("I2", Range("G" & Rows.Count).End(xlUp).Offset(, 2)).FormulaR1C1 = "=CONCATENATE(RC[-6],RC[-2])"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,594
Members
452,656
Latest member
earth

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