vba to add text after "=" Sign

mdd16

Board Regular
Joined
Jan 11, 2011
Messages
84
Office Version
  1. 365
Platform
  1. Windows
Hello

I have created a code to enter prefix and suffix to formula in the selected range. I have form which collects input and then puts back the new values in the cells adding prefix and suffix to the existing string.

I want to take the next step and be able to insert the new string after the "=" sign.
Example : Existing formula = "=B2"
Required New formula ="=If(A1=0,0,B2)

I am collecting new string from an input form. But I don't know how to add that string after the "=" sign.

Screen shot of my form is attached.

Can someone help.... please.
 

Attachments

  • Pasted_Image_23_06_2021__11_07_PM.jpg
    Pasted_Image_23_06_2021__11_07_PM.jpg
    139.2 KB · Views: 13

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
try this:
VBA Code:
Sub test()
Prefix = "If(A1=0,0,"
suffix = ")"
 Dim SelR As Range
 For Each SelR In Selection
      SelR.Formula = "=" & Prefix & Mid(SelR.Formula, 2) & suffix
 Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

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