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

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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

steve the fish

Well-known Member
Joined
Oct 20, 2009
Messages
8,861
Office Version
  1. 365
Platform
  1. Windows
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

cornepiek

New Member
Joined
Jun 22, 2010
Messages
48
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

cornepiek

New Member
Joined
Jun 22, 2010
Messages
48
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,191,721
Messages
5,988,303
Members
440,148
Latest member
sandy123

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
Top