VBA Showing a Difference

Dwergkip

New Member
Joined
Sep 24, 2014
Messages
48
Hello,

I want to show the difference between 2 values.
PROBLEM is.. It's in the same cell.
I get 1 value, and when I click on my commandbutton it changes.
Now I Want to show the difference between these 2 in the Cell below

Q4 = where the value is.
Q6 = where I want the difference to be displayed.

If this is too hard I had another idea:
Showing both Previous and current value.
All I have to do is Current - Previous.

But.. What I want is: Current value is always shown
Then when I click the commandbutton I want the current value to become Previous value and then to show the NEW Current value.

I Hope someone can help me.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I get 1 value, and when I click on my commandbutton it changes.
Now I Want to show the difference between these 2 in the Cell below

Q4 = where the value is.
Q6 = where I want the difference to be displayed.
How about something like this?
Code:
    Dim Num1 As Double

    Num1 = Range("Q4").Value
    'change Number here
    Range("Q6") = Range("Q4") - Num1
 
Upvote 0
Thanks for the try, but it does not work.
It shows: 0,00 While the difference was 25.

Q3 (not Q4, my bad) is the cell that displays the value
Q6 is the cell that shows the difference.

So for example: if Q3 = 25 and changes to 30, Q6 must display 5,00
But if Q3 = 25 and changes to 20, Q6 must display -5,00
 
Upvote 0
:confused:Using this on one of my sheets, worked happily
Code:
Sub chngNum()


    Dim Num1 As Double

    Num1 = Range("Q3").Value
    Range("Q3").Value = randbetween(1, 56)
    Range("Q6") = Range("Q3") - Num1

End Sub
Is the button on the same sheet?
Also do you have change events running on that sheet?
 
Upvote 0
Yes, the button is on the same sheet, and no, naot that I know of.

what exactly happends: I click the commandbutton. This gives a Randomnumber
Then when this number meets criteria, Q3 changes. Could be +1 or even +100000000.
Depends on what criteria is met.
Then, the next Commandbutton click does the same thing, but maybe other criteria ?
Then Q3 changes again.
I want to display the difference.
 
Upvote 0
Could you post the code that you already have?
 
Upvote 0
I get 1 value, and when I click on my commandbutton it changes.
How are these 2 values generated?
 
Upvote 0
Code:
If "lots of stuff that doesn't matter for this"
Else
c = IIf(c = 10, 0, c)
    c = c + 1
    RN = WorksheetFunction.RandBetween(0, 36)
    Cells(c + 11, "S") = RN
    Range("S8") = RN
End If
 
Upvote 0
Code:
If "lots of stuff that doesn't matter for this"
Else
c = IIf(c = 10, 0, c)
    c = c + 1
    RN = WorksheetFunction.RandBetween(0, 36)
    Cells(c + 11, "S") = RN
    Range("S8") = RN
End If

That is the Randomnumber generator.

The values in Q3 aren't really generated. But Its the easiest way to explain.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,981
Members
448,538
Latest member
alex78

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