Iferror index match formula

Apple08

Active Member
Joined
Nov 1, 2014
Messages
450
Hi everyone

I have a problem to copy and paste in the index match formula to the last row. I suppose I2 and J2 formulas should be pasted in until the last row. however I noticed the macro below doesn't refer to the right cell after paste:

Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Dim LastRow As Long[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]LastRow = Range("A" &Rows.Count).End(xlUp).Row[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]  Range("I2").Select[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveCell.FormulaR1C1 = _[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]       "=IFERROR(INDEX(Cost!C1:C3,MATCH('V&A'!RC5,Cost!C1,FALSE),3),"""")"[/COLOR][/SIZE][/FONT]


[FONT=Calibri][SIZE=3][COLOR=#000000]   Range("J2").Select[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000] ActiveCell.FormulaR1C1= _[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]       "=IFERROR(INDEX(Cost!C1:C3,MATCH('V&A'!RC5,Cost!C1,FALSE),3),"""")"[/COLOR][/SIZE][/FONT]


[FONT=Calibri][SIZE=3][COLOR=#000000] Range("M2").Select[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]  ActiveCell.FormulaR1C1 = "=IFERROR(RC8*RC9,0)"[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]   Range("I2:I" & LastRow).FillDown[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]  Range("J2:J" & LastRow).FillDown[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]  Range("M2:M" & LastRow).FillDown[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]   Range("M1").Value = "Total Cost"[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]  Range("I:I,J:J,M:M").NumberFormat = "0.00"[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]   'Format Total[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]   Range("L1").Select[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]   Selection.Copy[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]  Range("M1").Select[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]   Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]       SkipBlanks:=False, Transpose:=False[/COLOR][/SIZE][/FONT]

[FONT=Calibri][SIZE=3][COLOR=#000000]   Application.CutCopyMode = False[/COLOR][/SIZE][/FONT]

I expect the formula '=IFERROR(INDEX(Cost!$A:$C,MATCH('V&A'!$E2,Cost!$A:$A,FALSE),3),"")' is in cell I2 and J2 then paste down to the last row of columns I and J respectively, so in I3 and J3 the formula will be update to E3 automatically. However, after I have run the macro, some formulas are not updated correctly based on the row number, e.g. in row 3 it refers to V&A E22 rather than V&A E3. If I pasted down manually then they are okay. So I wonder is there something wrong with my macro? Many thanks.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about
Code:
   LastRow = Range("A" & Rows.Count).End(xlUp).Row

   Range("I2:I" & LastRow).FormulaR1C1 = "=IFERROR(INDEX(Cost!C1:C3,MATCH('V&A'!RC5,Cost!C1,FALSE),3),"""")"
   Range("J2:J" & LastRow).FormulaR1C1 = "=IFERROR(INDEX(Cost!C1:C3,MATCH('V&A'!RC5,Cost!C1,FALSE),3),"""")"
   Range("M2:M" & LastRow).FormulaR1C1 = "=IFERROR(RC8*RC9,0)"
   Range("M1").Value = "Total Cost"
   Range("I:I,J:J,M:M").NumberFormat = "0.00"
 
Upvote 0
Thanks Fluff. The formula in I2 and J2 appears as =IFERROR(INDEX(Cost!$A:$C,MATCH('V&A'!$E4,Cost!$A:$A,FALSE),3),"")

it should be V&A!E2

The formula in I3 and J3 appears as =IFERROR(INDEX(Cost!$A:$C,MATCH('V&A'!$E22,Cost!$A:$A,FALSE),3),"")

it should be V&A!E3

I don't understand what's wrong with the macros. If I update the formula in I2 and J2 to V&A!E2 then paste down manually and they work. So I wonder is there something wrong with the macro formula....
 
Upvote 0
Do you have any merged cells on any of those sheets?
 
Upvote 0
You cannot send it to me, but you can upload to a share site such as OneDrive, DropBox, GoogleDrive. Mark for sharing & then post the link to the thread.
 
Upvote 0
Hi Fluff, I finally found out it's the sorting in the macro, once the report is sorted the formulas are messed up. I have now moved the sorting before the input of formulas, however I have a question is how to ensure the index match formula won't be messed up once a report column order is sorted? Thanks.
 
Upvote 0
Glad to hear you've sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,207
Members
448,554
Latest member
Gleisner2

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