Inserting formula into cell through vba command

VBAlearner4work

New Member
Joined
Sep 17, 2018
Messages
3
Hi everyone,
I'm getting quite confused with a VBA code that i'm trying to implement.

I have a formula which consists out of several concatenated parts, which needs to be assigned to a specific cell:

.Range("C1").Formula="INDEX(E" & Cstr(i) & ":AA" & Cstr(i) & ";1;MATCH($D$17;$E$2:$AA$2;0))"

in which i is an iterator(1,2,3...).

i get an error trying to run this, and have pinpointed the error to the part:

.Range("C1").Formula="INDEX(E"

which gives the same error.

any help is appreciated :)


kind regards,
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Welcome to the MrExcel board!

Try replacing those semicolons with commas (even thouigh your version may use semicolons in worksheet formulas)

.Range("C1").Formula="INDEX(E" & Cstr(i) & ":AA" & Cstr(i) & ";1;MATCH($D$17;$E$2:$AA$2;0))"
 
Upvote 0
What is the error? What is the value of i when that line executes?
 
Upvote 0
Welcome to the MrExcel board!

Try replacing those semicolons with commas (even thouigh your version may use semicolons in worksheet formulas)

.Range("C1").Formula="=INDEX(E" & Cstr(i) & ":AA" & Cstr(i) & ";1;MATCH($D$17;$E$2:$AA$2;0))"

It also needs another equals sign.
 
Upvote 0
Hi everyone,
the semicolons definitely were the reason of the error.
("i" is just any integer number)
The code now manages to put the formula string into the cell , however it doesn't evaluate immediately.
I have to manually select the cell, click inside the text box and press enter to convert the actual function
how do i solve this?

Thanks a lot already.
kind regards.
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

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