Formula too long

cornepiek

New Member
Joined
Jun 22, 2010
Messages
48
Hi ALl

Can someone please help me, i am trying to use a formula in a VBA script but it seems the formula is too long

The formula works perfectly in the cell, but when i try to insert it on the VBA script, i get a Runtime 1004 error.

This is my insanely cumbersome formula


=IFERROR(VLOOKUP((LEFT(A2,12))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,11))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,10))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,9))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,8))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,7))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,6))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,5))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,4))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,3))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,2))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,1))+0,PIP!$A:$D,4,FALSE),""))))))))))))

Can anyone please help me so simplify it without losing the functionality
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try

=IFERROR(VLOOKUP((LEFT(A2,12))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,11))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP(( LEFT(A2,10))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,9))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,8))+0,PIP!$ A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,7))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,6))+0,PIP!$A:$D,4,FALSE),IFERRO R(VLOOKUP((LEFT(A2,5))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,4))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,3 ))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,2))+0,PIP!$A:$D,4,FALSE),IFERROR(VLOOKUP((LEFT(A2,1))+0,PIP!$A:$D,4,FAL SE),""""))))))))))))
 
Upvote 0
Recorded macros with long formulas seem to fail because excel cuts around 10 (I forget) characters from the VBA before the underscore/next line. Well it does on my 2010 version.
 
Upvote 0
here is what the macro recorder captures


ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP((LEFT(RC[-2],12))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],11))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],10))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],9))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],8))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],7))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],6))+0,PIP!C" & _
"ALSE),IFERROR(VLOOKUP((LEFT(RC[-2],5))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],4))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],3))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],2))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],1))+0,PIP!C1:C4,4,FALSE),""""))))))))))))"
Range("C3").Select


i see that it misses some info on the breaks

lm going to try to write it manualy
 
Upvote 0
This is the manual entry

Range("C2").Select


ActiveCell.FormulaR1C1 = _
"=IFERROR(VLOOKUP((LEFT(RC[-2],12))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],11))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],10))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],9))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],8))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],7))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],6))+0,PIP!" & _
"C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],5))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],4))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],3))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],2))+0,PIP!C1:C4,4,FALSE),IFERROR(VLOOKUP((LEFT(RC[-2],1))+0,PIP!C1:C4,4,FALSE),""""))))))))))))"
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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