Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Edit text of formula

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

--
achidsey
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Edit text of formula

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
--
HTH...

Jim Thomlinson


"achidsey" wrote:

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

--
achidsey

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default Edit text of formula

Thanks Jim,

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

Alan
--
achidsey


"Jim Thomlinson" wrote:

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
--
HTH...

Jim Thomlinson


"achidsey" wrote:

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

--
achidsey

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mystery text box I can't edit GaudiGill Excel Discussion (Misc queries) 6 April 24th 23 03:41 AM
Edit text into one cell? pvdm Setting up and Configuration of Excel 1 March 21st 07 09:25 PM
can macro edit text? LydiaD Excel Worksheet Functions 7 October 27th 06 07:38 AM
Edit Text Import Jim Link Excel Programming 0 August 19th 04 10:09 PM
Edit Text in Button ianripping[_32_] Excel Programming 6 February 7th 04 11:37 AM


All times are GMT +1. The time now is 10:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"