How to autofill the formulas in the column until the last row

Kenor

Board Regular
Joined
Dec 8, 2020
Messages
116
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I need help to edit below formula.

I want to autofill the formulas starting with the IFERROR (G2) in the column G until the last row that contains the data in the cells next to it (Column C, D, E & I).

Column C,D, E & I is the cells that the IFERROR refers to.



Sub fill_all_column()

' Fill the range G2 till
EndRow

Dim rg As Range

Dim cll As Range


Set rg = Range("G2:
EndRow")


For Each cll In rg

cll.FormulaR1C1 = "=IFERROR(INDEX('Register OUT'!R3C:R2000C11,MATCH(1,(DataBase!
R2C3='Register OUT'!R3C3:R2000C3)*(DataBase!R2C4='Register OUT'!R3C4:R2000C4)*(DataBase!R2C5='Register OUT'!R3C5:R2000C5)*(DataBase!R2C9='Register OUT'!R3C9:R2000C9),0),7),0)"

End Sub



Highlighted with red color need to change depends on rows number.


Thank you.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
try this
VBA Code:
Sub fill_all_column()

' Fill the range G2 till EndRow

Dim rg As Range

Dim cll As Range


Set rg = Range("G2:G" & cells(rows.count,4).end(xlup).row)
rg.filldown
end sub
 
Upvote 0
try this
VBA Code:
Sub fill_all_column()

' Fill the range G2 till EndRow

Dim rg As Range

Dim cll As Range


Set rg = Range("G2:G" & cells(rows.count,4).end(xlup).row)
rg.filldown
end sub

I already try above code but become like this..

1646958089839.png


I actually want the formula in cell G2 to copy to each cells until the last row.
FormulaR1C1 for G2 = "=IFERROR(INDEX('Register OUT'!R3C:R2000C11,MATCH(1,(DataBase!R2C3='Register OUT'!R3C3:R2000C3)*(DataBase!R2C4='Register OUT'!R3C4:R2000C4)*(DataBase!R2C5='Register OUT'!R3C5:R2000C5)*(DataBase!R2C9='Register OUT'!R3C9:R2000C9),0),7),0)"

But, the row number in the formula above (highlighted with red color) will be changed when copying to each cell.

For example =

G3 = "=IFERROR(INDEX('Register OUT'!R3C:R2000C11,MATCH(1,(DataBase!
R3C3='Register OUT'!R3C3:R2000C3)*(DataBase!R3C4='Register OUT'!R3C4:R2000C4)*(DataBase!R3C5='Register OUT'!R3C5:R2000C5)*(DataBase!R3C9='Register OUT'!R3C9:R2000C9),0),7),0)"

G4 = "=IFERROR(INDEX('Register OUT'!R3C:R2000C11,MATCH(1,(DataBase!R4C3='Register OUT'!R3C3:R2000C3)*(DataBase!R4C4='Register OUT'!R3C4:R2000C4)*(DataBase!R4C5='Register OUT'!R3C5:R2000C5)*(DataBase!R4C9='Register OUT'!R3C9:R2000C9),0),7),0)"

and so on...
 
Upvote 0
G3 = "=IFERROR(INDEX('Register OUT'!R3C:R2000C11

Should that be G3 = "=IFERROR(INDEX('Register OUT'!R3C11:R2000C11
?

Something is missing there.
 
Upvote 0
G3 = "=IFERROR(INDEX('Register OUT'!R3C:R2000C11

Should that be G3 = "=IFERROR(INDEX('Register OUT'!R3C11:R2000C11
?

Something is missing there.


Original formula from excel for G2 as below


=IFERROR(INDEX('Register OUT'!$A$3:$K$2000,MATCH(1,(DataBase!$C$2='Register OUT'!$C$3:$C$2000)*(DataBase!$D$2='Register OUT'!$D$3:$D$2000)*(DataBase!$E$2='Register OUT'!$E$3:$E$2000)*(DataBase!$I$2='Register OUT'!$I$3:$I$2000),0),7),0)


FormulaR1C1 = "=IFERROR(INDEX('Register OUT'!R3C:R2000C11,MATCH(1,(DataBase!R2C3='Register OUT'!R3C3:R2000C3)*(DataBase!R2C4='Register OUT'!R3C4:R2000C4)*(DataBase!R2C5='Register OUT'!R3C5:R2000C5)*(DataBase!R2C9='Register OUT'!R3C9:R2000C9),0),7),0)"


Please correct me if I'm wrong.
 
Upvote 0
FormulaR1C1 = "=IFERROR(INDEX('Register OUT'!R3C1:R2000C11,MATCH(1,(DataBase!R2C3='Register OUT'!R3C3:R2000C3)*(DataBase!R2C4='Register OUT'!R3C4:R2000C4)*(DataBase!R2C5='Register OUT'!R3C5:R2000C5)*(DataBase!R2C9='Register OUT'!R3C9:R2000C9),0),7),0)"


Correction made.
 
Upvote 0
According to your previous posts in this thread about what you want to change in the original formula ... the original formula for G2 should be:
=IFERROR(INDEX('Register OUT'!$A$3:$K$2000,MATCH(1,(DataBase!$C2='Register OUT'!$C$3:$C$2000)*(DataBase!$D2='Register OUT'!$D$3:$D$2000)*(DataBase!$E2='Register OUT'!$E$3:$E$2000)*(DataBase!$I2='Register OUT'!$I$3:$I$2000),0),7),0)
 
Upvote 0
Which leads to the following code:

VBA Code:
Sub DragDownFormula()
'
    Dim LastRowInColumn     As Long
'
    LastRowInColumn = Range("C" & Rows.Count).End(xlUp).Row                                 ' Returns the Last Row Number used of the C column
    Range("G2").AutoFill Destination:=Range("G2:G" & LastRowInColumn), Type:=xlFillDefault  ' Fills the formula from G2 down the G column
End Sub
 
Upvote 0
Which leads to the following code:

VBA Code:
Sub DragDownFormula()
'
    Dim LastRowInColumn     As Long
'
    LastRowInColumn = Range("C" & Rows.Count).End(xlUp).Row                                 ' Returns the Last Row Number used of the C column
    Range("G2").AutoFill Destination:=Range("G2:G" & LastRowInColumn), Type:=xlFillDefault  ' Fills the formula from G2 down the G column
End Sub

Yes..this formula to copy from G2 and paste down the G column.

FormulaR1C1 for G2 = "=IFERROR(INDEX('Register OUT'!R3C1:R2000C11,MATCH(1,(DataBase!R2C3='Register OUT'!R3C3:R2000C3)*(DataBase!R2C4='Register OUT'!R3C4:R2000C4)*(DataBase!R2C5='Register OUT'!R3C5:R2000C5)*(DataBase!R2C9='Register OUT'!R3C9:R2000C9),0),7),0)"

But, the row number in the formula above (highlighted with red color) will be changed when copying to each cell.

For example =

G3 = "=IFERROR(INDEX('Register OUT'!R3C1:R2000C11,MATCH(1,(DataBase!R3C3='Register OUT'!R3C3:R2000C3)*(DataBase!R3C4='Register OUT'!R3C4:R2000C4)*(DataBase!R3C5='Register OUT'!R3C5:R2000C5)*(DataBase!R3C9='Register OUT'!R3C9:R2000C9),0),7),0)"

G4 = "=IFERROR(INDEX('Register OUT'!R3C1:R2000C11,MATCH(1,(DataBase!R4C3='Register OUT'!R3C3:R2000C3)*(DataBase!R4C4='Register OUT'!R3C4:R2000C4)*(DataBase!R4C5='Register OUT'!R3C5:R2000C5)*(DataBase!R4C9='Register OUT'!R3C9:R2000C9),0),7),0)"

and so on...
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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