Big formula through VBA

abidraza

New Member
Joined
Feb 23, 2011
Messages
10
Range("F5:F1004").Formula = "=IF('Student Data'!E2<'Gross Fee Monthly'!$F$2,IF('Student Data'!H2=Setups!$C$2,IF(Setups!$F$2=Setups!$A$2,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$3:$E$17,2,FALSE),IF(Setups!$F$2=Setups!$A$3,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$20:$E$34,2,flase),IF(Setups!$F$2=Setups!$A$4,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$37:$E$51,2,FALSE),IF(Setups!$F$2=Setups!$A$5,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$54:$E$68,2,FALSE),IF(Setups!$F$2=Setups!$A$6,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$71:$E$85,2,FALSE),IF(Setups!$F$2=Setups!$A$7,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$88:$E$102,2,FALSE),IF(Setups!$F$2=Setups!$A$8,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$105:$E$119,2,FALSE),IF(Setups!$F$2=Setups!$A$9,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$122:$E$136,2,FALSE),IF(Setups!$F$2=Setups!$A$10,VLOOKUP('Fee structure'!$A$139:$E$153,2,FALSE),IF(Setups!$F$2=Setups!$A$11,_"
&"VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$155:$E$169,2,FALSE),))))))_"
& )))),IF('Student Data'!I2<='Gross Fee Monthly'!$F$2,0,IF(Setups!$F$2=Setups!$A$2,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$3:$E$17,2,FALSE),IF(Setups!$F$2=Setups!$A$3,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$20:$E$34,2,flase),IF(Setups!$F$2=Setups!$A$4,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$37:$E$51,2,FALSE),IF(Setups!$F$2=Setups!$A$5,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$54:$E$68,2,FALSE),IF(Setups!$F$2=Setups!$A$6,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$71:$E$85,2,FALSE),IF(Setups!$F$2=Setups!$A$7,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$88:$E$102,2,FALSE),IF(Setups!$F$2=Setups!$A$8,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$105:$E$119,2,FALSE),IF(Setups!$F$2=Setups!$A$9,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$122:$E$136,2,FALSE),IF(Setups!$F$2=Setups!$A$10,VLOOKUP('Fee structure'!$A$139:$E$153,2,FALSE),IF(Setups!$F$2=Setups!$A$11,VLOOKUP('Gross Fee Monthly'!D5,'Fee structure'!$A$155:$E$169,2,FALSE),)))))))))))))



How to put this formula though VBA
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You're going to have to shorten your formula. Try:

Code:
Sub Test()
    Dim Formula As String
    Formula = "=IF('Student Data'!E2<'Gross Fee Monthly'!$F$2,"
    Formula = Formula & "IF('Student Data'!H2=Setups!$C$2,"
    Formula = Formula & "VLOOKUP('Gross Fee Monthly'!D5,OFFSET('Fee structure'!$A$3:$E$170,(MATCH(Setups!$F$2,Setups!$A$2:$A$11,FALSE)-1)*17,0,15),2,FALSE)),"
    Formula = Formula & "IF('Student Data'!I2<='Gross Fee Monthly'!$F$2,0,"
    Formula = Formula & "VLOOKUP('Gross Fee Monthly'!D5,OFFSET('Fee structure'!$A$3:$E$170,(MATCH(Setups!$F$2,Setups!$A$2:$A$11,FALSE)-1)*17,0,15),2,FALSE)))"
    Range("F5:F1004").Formula = Formula
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

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