Excel VBA : Appending string with a variable

sachinns

Board Regular
Joined
Jun 21, 2019
Messages
52
Hi Friends,

I have a string and a variable called "Formula". I want to append this string with my variable and update this value in the Cells(Lastrow, 3) of my active sheet.

String is :

=IFERROR(IF(O9=” + Formula + " ;””);”Missing Leader Price”) "

Note : Orange part is my string

I tried to do it but its showing error. Can somebody help me to provide the vba code for this.

Thanks
 
Last edited:
@Fluff
It is showing the text in msgbox. The text in textbox3 is showing in the msgbox.
eg : | "text" |

@Fluff
When my string is just "hello" then it is working fine. please check.

Code:
Dim Formula As String
Formula = TextBox3
MsgBox "|" & Formula & "|"
Cells(Lastrow, 3).Formula = "Hello" & Formula
 
Last edited:
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
That works fine for me.
Try
Code:
Dim MyFormula As String
MyFormula = TextBox3
Cells(Lastrow, 3).Formula = "=IFERROR(IF(O9=" & MyFormula & " ,""""),""Missing Leader Price"")"
It's best to avoid using VBA keywords (such as Formula) for the names of variables or procedures, as VBA can sometimes get confused.
 
Upvote 0
@Fluff

Code:
Dim MyFormula As String
MyFormula = TextBox3
'MsgBox "|" & MyFormula & "|"
Cells(Lastrow, 3).Formula = "(IF(O9=" + MyFormula + " ,"""");""Missing Leader Price"")"

This part of string is also working fine.

When i add this part of the string "=IFERROR" Then it is not working.

I think VBA is not considering IFERROR as a string.
 
Last edited:
Upvote 0
In that case you have probably got a variable, function, sub or some other procedure called IFERROR.
Check all your code
 
Upvote 0
@Fluff

In this UserForm, I never used IFERROR as variable, function, sub or some other procedure anywhere. :(

Please help me.
 
Last edited:
Upvote 0
Not just in the userform, anywhere in that workbook.
 
Upvote 0
@Fluff

The workbook is very very big. The file size 30MB + . =IFERROR is there in so many modules and functions.

So is there any way i can add this string without changing the other modules and functions ???
 
Upvote 0
Your code works fine for me, so it is not a problem with that line of code.
If you have used IFERROR as the name of a variable or procedure you will need to change it.
 
Upvote 0
@Fluff

I found the issue. It is not because i have used IFERROR as the name of variable . It is because we cannot write a string to a cell which starts with "=" . Because it will be considered as formula. So we have to use '= .

Thanks a lot for your valuable time.

Code:
Cells(Lastrow, 3).Formula = "'=IFERROR(IF(O9=" + MyFormula + " ,"""");""Missing Leader Price"")"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,569
Members
453,053
Latest member
Kiranm13

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