Removing + or - if they exist in cell

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
189
I am copying data between some sheets with my vba and some of the cells pasted start with a minus or plus sign.

This is causing them to come up with a name error and also causing errors in my code.

The original data (pasted from another program) has cells starting with plus or minus and this is making excel see them as a formula.

I want to remove these - so when they are pasted, they come out as "=-etc" or "=+etc" so excel is adding the = to the front.

What is the best way to fix this?

Thinking of something like if the first two letters are "=-" or "=+" then remove the first two letters??

Any help appreciated.


Thanks
Tom
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Does this formula return what you require?

=VALUE(RIGHT(A2,LEN(A2) - MIN(SEARCH({0,1,2,3,4,5,6,7,8,9}, A2&"0123456789")) +1))
 
Upvote 0
Hi Yongle,

Thanks but no it doesn't.

I've maybe not explained it very well.

I want to manipulate the cell value through VBA of cells.


The cells are written into a scripting dictionary and if they are prefixed with + or - it is causing problems. This is only for a few cells out of thousands, but there will occasionally be this issue.

So if the cell value starts with + or -, it comes up in excel as #NAME and excel makes its formula "=-etc...." or "=+etc....."

So if this is the case then I want to get rid of the formula bit at the front.


Thanks
Tom
 
Upvote 0
Have you tried selecting the range and using Excel Find and Replace?

equals plus.jpg




Find =+ and replace with nothing
Find =- and replace with nothing

It works for me
eg
BEFORE:
cell contents
=+tsts ysdydyd
cell returns
#NAME?

AFTER:
cell contents
tsts ysdydyd
cell returns
tsts ysdydyd
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,823
Members
449,049
Latest member
cybersurfer5000

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