Edit text of formula

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Excel Experts,

Is there code that will edit a formula based on the text in the formula.

The formulas in my spreadsheet are similar to the following

A B C
1 =200-100
2 =3000-2400
3 =50-25

What I want to do is edit these formulas by stripping out the minus sign and
anything after the minus sign.

So I want to edit A1 "=200-100" by deleting "-100", so that the resulting
formula is "=200".

Is there code that would do this?

Thanks,
Alan
 
Here is a function that does what you want (I think...)

Public Function BeforeMinus(ByVal Cell As Range) As String
Dim strReturnValue As String

strReturnValue = "Error"
If Left(Cell.Formula, 1) = "=" And InStr(Cell.Formula, "-") Then
strReturnValue = Left(Cell.Formula, InStr(Cell.Formula, "-") - 1)
End If
BeforeMinus = strReturnValue
End Function
 
Thanks Jim,

I want to put it in a sub procedure but hopefully I can make the coversion.

Alan
 
Hi achidsey

Try...

Sub Test()
Range("A1:A100").Replace What:="-*", Replacement:="", LookAt:=xlPart
End Sub

--


XL2003
Regards

William
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top