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.
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,529
Office Version
  1. 365
Platform
  1. Windows
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
 

Dwergkip

New Member
Joined
Sep 24, 2014
Messages
48
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,529
Office Version
  1. 365
Platform
  1. Windows
: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?
 

Dwergkip

New Member
Joined
Sep 24, 2014
Messages
48

ADVERTISEMENT

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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,529
Office Version
  1. 365
Platform
  1. Windows
Could you post the code that you already have?
 

Dwergkip

New Member
Joined
Sep 24, 2014
Messages
48

ADVERTISEMENT

I don't have a code for this part yet. Thats why I am asking.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,529
Office Version
  1. 365
Platform
  1. Windows
I get 1 value, and when I click on my commandbutton it changes.
How are these 2 values generated?
 

Dwergkip

New Member
Joined
Sep 24, 2014
Messages
48
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
 

Dwergkip

New Member
Joined
Sep 24, 2014
Messages
48
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,329
Messages
5,528,033
Members
409,799
Latest member
mlewan_ca

This Week's Hot Topics

Top