Help Amending VBA code

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
586
Office Version
  1. 2013
Platform
  1. Windows
Hi Guy's

I am quick new to VBA code and bit rusty.

I am trying to amend the VBA Code my being a fixed last row to a dynamic i.e using the lastrow variable.

I just cannot seem to get the syntax right.

Your help would be greatly appreciated.

VBA Code:
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
     
    Range("D2").FormulaArray = "=IFERROR(INDEX(Assignment!$H$3:$H$429,MATCH(1,(A2=Assignment!$A$3:$A$429)*($D$1=Assignment!$H$3:$H$429),0)),"""")"
    Range("E2").FormulaArray = "=IFERROR(INDEX(Assignment!$D$3:$D$429,MATCH(1,(A2=Assignment!$A$3:$A$429)*($D$1=Assignment!$H$3:$H$429),0)),"""")"
    Range("D2:E" & lastrow).FillDown
 

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:
VBA Code:
 Range("D2").Select
    ActiveCell.FormulaR1C1 = "=IFERROR(INDEX(Assignment!$H$3:$H$429,MATCH(1,(A2=Assignment!$A$3:$A$429)*($D$1=Assignment!$H$3:$H$429),0)),"""")"
Range("E2").Select
   ActiveCell.FormulaR1C1  = "=IFERROR(INDEX(Assignment!$D$3:$D$429,MATCH(1,(A2=Assignment!$A$3:$A$429)*($D$1=Assignment!$H$3:$H$429),0)),"""")"
    Selection.AutoFill Destination:=Range("M2:E" & Range("A" & Rows.count).End(xlUp).Row)
    Range(Selection, Selection.End(xlDown)).Select
 
Upvote 0
Try:
VBA Code:
 Range("D2").Select
    ActiveCell.FormulaR1C1 = "=IFERROR(INDEX(Assignment!$D$3:$D$429,MATCH(1,(A2=Assignment!$A$3:$A$429)*($D$1=Assignment!$H$3:$H$429),0)),"""")"
Range("E2").Select
   ActiveCell.FormulaR1C1  = "=IFERROR(INDEX(Assignment!$D$3:$D$429,MATCH(1,(A2=Assignment!$A$3:$A$429)*($D$1=Assignment!$H$3:$H$429),0)),"""")"
    Selection.AutoFill Destination:=Range("M2:E" & Range("A" & Rows.count).End(xlUp).Row)
    Range(Selection, Selection.End(xlDown)).Select
Hi BigBeachBananas

I am sorry if i did not explain my question correctly

I was referring to the !$D$3:$D$429, $A$3:$A$429, $H$3:$H$429 parts of the code.

Regards
 
Upvote 0
Hi BigBeachBananas

I am sorry if i did not explain my question correctly

I was referring to the !$D$3:$D$429, $A$3:$A$429, $H$3:$H$429 parts of the code.

Regards
No problem, I think you need to use & and "" to concatenate. I don't have excel to test atm but: something like this:
VBA Code:
 Range("D2").FormulaArray = "=IFERROR(INDEX(Assignment!$H$3:$H$" & lastrow & ",MATCH(1,(A2=Assignment!$A$3:$A$"& last row & ")*($D$1=Assignment!$H$3:$H$" & lastrow & "),0)),"""")"
 
Upvote 0
Using a place holder and then the replace command seems quite a popular way of achieving this.
In the below "#" is the place holder for the last row number.

VBA Code:
    Range("D2").FormulaArray = Replace( _
                                    "=IFERROR(INDEX(Assignment!$H$3:$H$#,MATCH(1,(A2=Assignment!$A$3:$A$#)*($D$1=Assignment!$H$3:$H$#),0)),"""")", _
                                    "#", lastrow)
    Range("E2").FormulaArray = Replace( _
                                    "=IFERROR(INDEX(Assignment!$D$3:$D$#,MATCH(1,(A2=Assignment!$A$3:$A$#)*($D$1=Assignment!$H$3:$H$#),0)),"""")", _
                                    "#", lastrow)
 
Upvote 0
Using a place holder and then the replace command seems quite a popular way of achieving this.
In the below "#" is the place holder for the last row number.

VBA Code:
    Range("D2").FormulaArray = Replace( _
                                    "=IFERROR(INDEX(Assignment!$H$3:$H$#,MATCH(1,(A2=Assignment!$A$3:$A$#)*($D$1=Assignment!$H$3:$H$#),0)),"""")", _
                                    "#", lastrow)
    Range("E2").FormulaArray = Replace( _
                                    "=IFERROR(INDEX(Assignment!$D$3:$D$#,MATCH(1,(A2=Assignment!$A$3:$A$#)*($D$1=Assignment!$H$3:$H$#),0)),"""")", _
                                    "#", lastrow)
Hi Alex
I hope you don't mind me reaching out to you.
You so kindly helped me a while back to insert the above formula into a range, and I have been trying to do the same with the formula below and just cannot get it to work.
Would mind helping me please?
This the formula in C2 =MAX(INDEX((A2=Assignment!$A$3:$A$431)*Assignment!$F$3:$F$431,0))

Thank again
 
Upvote 0
This probably should be a new thread but see if this is what you are after:-
VBA Code:
    Range("C2").FormulaArray = Replace( _
                                    "=IFERROR(MAX(INDEX((A2=Assignment!$A$3:$A$#)*Assignment!$F$3:$F$#,0)),"""")", _
                                    "#", lastrow)
 
Upvote 0
This probably should be a new thread but see if this is what you are after:-
VBA Code:
    Range("C2").FormulaArray = Replace( _
                                    "=IFERROR(MAX(INDEX((A2=Assignment!$A$3:$A$#)*Assignment!$F$3:$F$#,0)),"""")", _
                                    "#", lastrow)
Thank you much appreciated.

Will start a new post next time.

Regards
Desmond
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

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