Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

macro to change negative value in excel 2

Status
Not open for further replies.

SharonMee

MIS
Joined
May 7, 2004
Messages
210
Location
CA
Hello all:

I need your urgent help with the following:

I want my macro to do the following:

If B10 is a negative value (b10 has a calculation in (b9-b11+b12)), I want the macro to: go to cell F14 and whatever the value is in cell f14, it should SUBTRACT the value of cell b10. i.e. F14 is now the existing value in F14-(b10) and b10 is negative, so the value of F14 actually increases.

I want excel to also simultaneously ADD the original value of b10 to cell F22. So, that means, that before all these additions and subtractions, excel should store the original value of B10 and then subtract it from F14, at the same time add the value to F22.

Thanks much for helping

SharonMee
 
And what have you so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi Sharon,

Seems trivial, what's the catch?

Code:
[blue]If [b10] < 0 Then
    [f14] = [f14] - [b10]
    [f22] = [f22] + [b10]
End If[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Thank you, Tony.

There is no catch, I didn't know how to represent what I wanted in VBA.

I tried it, worked, and I have to add more things to it. If I have any questions, I'll repost.

Thanks again.

SharonMee
 
Hi try simething like:

dim a as variant
dim b as variant

a = worksheets("Sheet1").cells(10,2).value ' cell B10
b = worksheets("Sheet1").cells(14,6).value ' cell F14

this gives you the actual value of cell B10 and cell F14 in VBA.

after that you have to subract the value "a" from "B" and place it in F14:

if a<0 then
worksheets("Sheet1").cells(14,6).value=b-a
end if

hope this will help!

Andrea
 
Thanks TonyJollans,

You also helped me! :-)

[pipe] "We know nothing but, that what we know is not the truth..." - Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top