Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Retrieve part of a calculation

I would like to scan a range of cells and if there is a calculation in
the cell, such as =5000 - 200, I would like to replace the value of
the cell with what is immediately to the right of the equals sign. In
this example I would like the new value of the cell to be 5000. All of
the calculations will be in the format of =n1 - n2, I need to get the
value of n1 and place it in the cell. If there is not a calculation in
the cell, I want to leave it unchanged. Can someone give me the logic
to do this?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Retrieve part of a calculation

On Mar 9, 3:26*pm, slowjam4 wrote:
I would like to scan a range of cells and if there is a calculation in
the cell, such as =5000 - 200, I would like to replace the value of
the cell with what is immediately to the right of the equals sign. In
this example I would like the new value of the cell to be 5000. All of
the calculations will be in the format of =n1 - n2, I need to get the
value of n1 and place it in the cell. If there is not a calculation in
the cell, I want to leave it unchanged. Can someone give me the logic
to do this?

Thanks


Check activecell.HasFormula and change activecell.Formula!
Regards,
Stefi
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 563
Default Retrieve part of a calculation

Sub Tryme()
Set myRange = Range("A1:A100")
For Each mycell In myRange
If mycell.HasFormula Then
myForm = mycell.Formula
minusChar = InStr(myForm, "-")
myValue = CLng(Mid(myForm, 2, minusChar - 2))
mycell.Offset(columnoffset:=1) = myValue
Else
mycell.Offset(columnoffset:=1) = mycell.Value
End If
Next
End Sub

best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme

"slowjam4" wrote in message
...
I would like to scan a range of cells and if there is a calculation in
the cell, such as =5000 - 200, I would like to replace the value of
the cell with what is immediately to the right of the equals sign. In
this example I would like the new value of the cell to be 5000. All of
the calculations will be in the format of =n1 - n2, I need to get the
value of n1 and place it in the cell. If there is not a calculation in
the cell, I want to leave it unchanged. Can someone give me the logic
to do this?

Thanks


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Retrieve part of a calculation

On Mar 9, 10:21*am, "Bernard Liengme"
wrote:
Sub Tryme()
*Set myRange = Range("A1:A100")
*For Each mycell In myRange
* If mycell.HasFormula Then
* *myForm = mycell.Formula
* *minusChar = InStr(myForm, "-")
* *myValue = CLng(Mid(myForm, 2, minusChar - 2))
* *mycell.Offset(columnoffset:=1) = myValue
* Else
* *mycell.Offset(columnoffset:=1) = mycell.Value
* End If
*Next
End Sub

best wishes
--
Bernard Liengme
Microsoft Excel MVPhttp://people.stfx.ca/bliengme

"slowjam4" wrote in message

...



I would like to scan a range of cells and if there is a calculation in
the cell, such as =5000 - 200, I would like to replace the value of
the cell with what is immediately to the right of the equals sign. In
this example I would like the new value of the cell to be 5000. All of
the calculations will be in the format of =n1 - n2, I need to get the
value of n1 and place it in the cell. If there is not a calculation in
the cell, I want to leave it unchanged. Can someone give me the logic
to do this?


Thanks- Hide quoted text -


- Show quoted text -


This is close but not exactly what I want. Original cell values:

A1 =300 - 100 B1 =100 - 50
A2 =500 - 200 B2 =600 - 300
A3 =100 - 50 B3 =800 - 400

Result after running the macro:

A1 200 B1 300
A2 300 B2 500
A3 50 B3 100

It is leaving A1, A2, A3 unchanged and placing the values in B1, B2,
B3

I was hoping for the following after running the macro:

A1 300 B1 100
A2 500 B2 600
A3 100 B3 800
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 563
Default Retrieve part of a calculation

New version
Sub Tryme()
Set myrange = Range("A1:B10")

For Each mycell In myrange
If mycell.HasFormula Then
MsgBox mycell.Formula
myForm = mycell.Formula
minusChar = InStr(myForm, "-")
myValue = CLng(Mid(myForm, 2, minusChar - 2))
mycell.Value = myValue
MsgBox mycell
Else
mycell.Value = mycell.Value
End If
Next
End Sub

best wishes
--
Bernard Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme



"slowjam4" wrote in message
...
On Mar 9, 10:21 am, "Bernard Liengme"
wrote:
Sub Tryme()
Set myRange = Range("A1:A100")
For Each mycell In myRange
If mycell.HasFormula Then
myForm = mycell.Formula
minusChar = InStr(myForm, "-")
myValue = CLng(Mid(myForm, 2, minusChar - 2))
mycell.Offset(columnoffset:=1) = myValue
Else
mycell.Offset(columnoffset:=1) = mycell.Value
End If
Next
End Sub

best wishes
--
Bernard Liengme
Microsoft Excel MVPhttp://people.stfx.ca/bliengme

"slowjam4" wrote in message

...



I would like to scan a range of cells and if there is a calculation in
the cell, such as =5000 - 200, I would like to replace the value of
the cell with what is immediately to the right of the equals sign. In
this example I would like the new value of the cell to be 5000. All of
the calculations will be in the format of =n1 - n2, I need to get the
value of n1 and place it in the cell. If there is not a calculation in
the cell, I want to leave it unchanged. Can someone give me the logic
to do this?


Thanks- Hide quoted text -


- Show quoted text -


This is close but not exactly what I want. Original cell values:

A1 =300 - 100 B1 =100 - 50
A2 =500 - 200 B2 =600 - 300
A3 =100 - 50 B3 =800 - 400

Result after running the macro:

A1 200 B1 300
A2 300 B2 500
A3 50 B3 100

It is leaving A1, A2, A3 unchanged and placing the values in B1, B2,
B3

I was hoping for the following after running the macro:

A1 300 B1 100
A2 500 B2 600
A3 100 B3 800




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Retrieve part of a calculation

On Mar 9, 5:07*pm, "Bernard Liengme"
wrote:
New version
Sub Tryme()
*Set myrange = Range("A1:B10")

*For Each mycell In myrange
* If mycell.HasFormula Then
* *MsgBox mycell.Formula
* *myForm = mycell.Formula
* *minusChar = InStr(myForm, "-")
* *myValue = CLng(Mid(myForm, 2, minusChar - 2))
* *mycell.Value = myValue
* *MsgBox mycell
* Else
* *mycell.Value = mycell.Value
* End If
*Next
End Sub

best wishes
--
Bernard Liengme
Microsoft Excel MVPhttp://people.stfx.ca/bliengme

"slowjam4" wrote in message

...



On Mar 9, 10:21 am, "Bernard Liengme"
wrote:
Sub Tryme()
*Set myRange = Range("A1:A100")
*For Each mycell In myRange
* If mycell.HasFormula Then
* *myForm = mycell.Formula
* *minusChar = InStr(myForm, "-")
* *myValue = CLng(Mid(myForm, 2, minusChar - 2))
* *mycell.Offset(columnoffset:=1) = myValue
* Else
* *mycell.Offset(columnoffset:=1) = mycell.Value
* End If
*Next
End Sub


best wishes
--
Bernard Liengme
Microsoft Excel MVPhttp://people.stfx.ca/bliengme


"slowjam4" wrote in message


....


I would like to scan a range of cells and if there is a calculation in
the cell, such as =5000 - 200, I would like to replace the value of
the cell with what is immediately to the right of the equals sign. In
this example I would like the new value of the cell to be 5000. All of
the calculations will be in the format of =n1 - n2, I need to get the
value of n1 and place it in the cell. If there is not a calculation in
the cell, I want to leave it unchanged. Can someone give me the logic
to do this?


Thanks- Hide quoted text -


- Show quoted text -


This is close but not exactly what I want. Original cell values:


A1 =300 - 100 * * * B1 =100 - 50
A2 =500 - 200 * * * B2 =600 - 300
A3 =100 - 50 * * * * B3 =800 - 400


Result after running the macro:


A1 200 * * *B1 300
A2 300 * * *B2 500
A3 50 * * * *B3 100


It is leaving A1, A2, A3 unchanged and placing the values in B1, B2,
B3


I was hoping for the following after running the macro:


A1 300 *B1 100
A2 500 *B2 *600
A3 100 *B3 *800- Hide quoted text -


- Show quoted text -


That worked exactly like I wanted it to. Thanks for the help.
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
Stopping Auto calculation in Part of a Worksheet Mhukki Excel Worksheet Functions 1 April 30th 08 05:04 PM
(Part 3) - Retrieve Numeric Label for Max Value by Criteria across Single Row Sam via OfficeKB.com Excel Worksheet Functions 2 February 21st 07 11:48 PM
(Part 2) - Retrieve Numeric Label for Max Value by Specific Day & Month Sam via OfficeKB.com Excel Worksheet Functions 4 February 21st 07 02:40 AM
i am working with excel sheet. in the calculation part i want if srinivas Excel Programming 1 April 27th 06 08:14 PM


All times are GMT +1. The time now is 01:55 AM.

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

About Us

"It's about Microsoft Excel"