VBA add text only if not there

dukeofscouts

Board Regular
Joined
Jan 19, 2009
Messages
146
Ok I've got a worksheet change code that runs to add the text "~~SPECIAL~~" to the target's value.

The issue is that as the working code runs the next time that cell is edited, the text reads:
~~SPECIAL~~
~~SPECIAL~~
target.value

I've tried to use Target.Replace to fix this, but to no avail. any suggestion?

Current code:
Target.value = "~~SPECIAL~~" & Chr(10) & Target.value
Code result:
~~SPECIAL~~
~~SPECIAL~~
Target.value

Attempted Code:
Target.replace ("~~SPECIAL~~", "")
Target.value = "~~SPECIAL~~" & Chr(10) & Target.value
Code result:
~~SPECIAL~~
~~
Target.value

Desired Code:
???
Code result:
~~Special~~
Target.value
 
May be
Code:
If Left(Target.Value, 11) <> "~~SPECIAL~~" Then
    Target.Value = "~~SPECIAL~~" & Chr(10) & Target.Value
End If
 
Upvote 0

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