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.
 
@Kenor, you keep saying the same thing over and over.

You didn't say what you consider is wrong with my last post.
 
Upvote 0

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
@Kenor your main issue is you have made your row numbers that you want to increment absolute in your formula, you can't increment them when they are absolute. Try....

VBA Code:
Sub Kenor()
Sheets("Database").Range("G2:G" & Sheets("Database").Range("C" & Rows.Count).End(xlUp).Row).Formula = "=IFERROR(INDEX('Register OUT'!$A3:$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)"
End Sub

Hi @MARK858

I have try your formula.

The result almost achieved what I wanted..:)

But formulas can be copied to each row when there is data in the adjacent column only.

1647224064412.png


Can you make it automatically copied even if there is no data?

And fyi, this formula also need to press Ctrl+Shift+Enter to complete the formula because use array formulas.

1647224247144.png


When press Ctrl+Shift+Enter

1647224466946.png


But it seems that the formula is unable to detect the correct data from the ‘Register OUT’ sheet.
 
Upvote 0
I think need to do some amendment on the VBA code.

Because the result shows as below;
(The formula captured the data from 'Register OUT' sheet)

G3 =
1647225318820.png


G4 =
1647225343125.png


G5 =
1647225369085.png
 
Upvote 0
@Kenor, you keep saying the same thing over and over.

You didn't say what you consider is wrong with my last post.
Sorry @johnnyL ?

I didn't change anything with your code.

I just copy and paste. But when I run it, the results show like that.

I'll try again.. maybe I should delete everything and start over.
 
Upvote 0
I already try this code, but sorry still can't solve..?

This is result when I try this code..

View attachment 59912

Yeahhh... almost done!

Your formula also work well.

Sorry, after I delete all and start again. Then, it's work!

1647226507835.png


But need help to run the formula by pressing ctrl-shift-enter
 
Upvote 0
@Kenor, If you are addressing me in your last post:

VBA Code:
Sub TestArrayFormulasCopyDown()
'
    Dim LastRowInColumn As Long
'
    LastRowInColumn = Range("C" & Rows.Count).End(xlUp).Row                                 ' Returns the Last Row Number used of the C column
'
    Range("G2").FormulaArray = "=IFERROR(INDEX('Register OUT'!$A$3:$K$" & LastRowInColumn & _
            ", MATCH(1,(DataBase!$C2='Register OUT'!$C$3:$C$" & LastRowInColumn & _
            ")*(DataBase!$D2='Register OUT'!$D$3:$D$" & LastRowInColumn & _
            ")*(DataBase!$E2='Register OUT'!$E$3:$E$" & LastRowInColumn & _
            ")*(DataBase!$I2='Register OUT'!$I$3:$I$" & LastRowInColumn & "),0),7),0)"      ' Copy formula to be used to Range("G2")
    Range("G2").AutoFill Destination:=Range("G2:G" & LastRowInColumn), Type:=xlFillDefault  ' Fill the formula from G2 down the G column
End Sub

Book1
ABCDEFGH
1
2C20
3C30
4C40
5C50
6C60
7C70
8C80
9C90
10C100
11
Sheet1
Cell Formulas
RangeFormula
G2:G10G2=IFERROR(INDEX('Register OUT'!$A$3:$K$10, MATCH(1,(DataBase!$C2='Register OUT'!$C$3:$C$10)*(DataBase!$D2='Register OUT'!$D$3:$D$10)*(DataBase!$E2='Register OUT'!$E$3:$E$10)*(DataBase!$I2='Register OUT'!$I$3:$I$10),0),7),0)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Solution
Yess...finally!

Thanks a lot @johnnyL

1647231057424.png


But maybe I need to create 1 button to run the formula.

Based on current practice, after I transfer the IN(Kg) data into the Database sheet.
I need to open the Visual Basic editor to run the formula.

Anyway, thank you again @johnnyL for your efforts to resolve this matter. :giggle::giggle:
 
Upvote 0
You are welcome @Kenor, I see you have altered the code again, as long as you are happy though.
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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