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:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try
Code:
cell(lastrow,3).formula="=IFERROR(IF(O9=" & Formula & " ,""""),""Missing Leader Price"")"
 
Upvote 0
@Fluff

Code:
Private Sub Validate_Click()
If ComboBox3.Text = "" Then
Cancel = 1
MsgBox "Please Enter the Formula Name"
ComboBox3.SetFocus
Exit Sub
End If
If TextBox2.Text = "" Then
Cancel = 1
MsgBox "Please Enter the Formula Description"
TextBox2.SetFocus
Exit Sub
End If


Set ws = ThisWorkbook.Worksheets("Formula")
ws.Activate

Dim Lastrow
Lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
Lastrow = Lastrow + 1
Cells(Lastrow, 1) = ComboBox3
Cells(Lastrow, 2) = TextBox2
'Cells(Lastrow, 3) = TextBox3
Dim Formula As String
Formula = TextBox3
'Cells(Lastrow, 3) = "=IFERROR(IF(O9=" + Formula '+ ";" + Chr(34)  + Chr(34))+ ";" + Chr(34)+ "Missing Leader Price" + Chr(34) + ")"
'Cells(Lastrow, 3).Formula = "H" '"=IFERROR(IF(O9=" & Formula & " ,""""),""Missing Leader Price"")"
End Sub

Note : I commented some part code .
 
Last edited:
Upvote 0
What line gives the error?
 
Upvote 0
The code which you gave.
Cells(Lastrow, 3).Formula = "=IFERROR(IF(O9=" & Formula & " ,""""),""Missing Leader Price"")"

@Fluff


 
Upvote 0
In that case I suspect that TextBox3 does not have a value.
 
Upvote 0
@Fluff

No, It is have the value. I can see the Text in the textbox.


If the string is "Hello" then i am able to append and update it into my sheet. But the string which i mentioned above is not working.
Please help me.
 
Last edited:
Upvote 0
If you add the message box as shown
Code:
Dim Formula As String
Formula = TextBox3
MsgBox "|" & Formula & "|"
Cells(Lastrow, 3).Formula = "=IFERROR(IF(O9=" & Formula & " ,""""),""Missing Leader Price"")"
What does it say?
 
Upvote 0

Forum statistics

Threads
1,224,875
Messages
6,181,516
Members
453,050
Latest member
Obil

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