Adding a button or macro to change values of cells?

Atheos22

New Member
Joined
Apr 6, 2015
Messages
5
I am trying to build a worksheet, and it would be very helpful to put a button in that manipulates the values of certain cells.



Above is what a row of my spread sheet looks like. What I want to do, is add a check mark box in N2 that, if checked, would do the following:

1, make the value of G2 = G2, since it's a formula and as soon as steps 2 and 3 are executed it will change the value.
2, add lets say 40 to E2, making it "83",
3, make F2 a value of zero (this step isn't necessary since I will be eliminating the formula in cell G2)

From what I understand you can't undo macros, so if there is any way to do this without using macros that would be perfect, or if there is a way to undo a macro and I don't know what it is, that would also be perfect.

I look forward to getting this workbook up and running, thanks for all your help!
 
I know you said you don't want to use macros, but incase you don't find a formula to do what you want....

Do you have an empty cell where you could store the formula used inside G2?
To make an UNDO MACRO, you would a permanently empty Cell.
That empty, uneeded cell can store the previous E2 Value
You then easily make a macro to restore your formula into G2, that is not a problem, and replace the E2 back to the original.

Assign this Macro to your button to do steps 1 and 2...

Code:
Sub Button1 ()
    Dim MyNumber As Integer
    
    'Make G2 Value Only / No Formula
        Range("G2").Value = Range("G2").Value
        
    'Ask for a number to place into Cell E2:
        MyNumber = Application.InputBox("What Number do you want to enter into ""Cell E2""?")
        'If User Hits Cancel, Or doesn't enter anything:
        If MyNumber = False Then
            MsgBox "User Cancelled"
            Exit Sub
        End If

    'Place the desired number into Cell E2
        Range("E2").Value = MyNumber

End Sub
 
Last edited:
Upvote 0
@Atheos22
may not be relevent but if the you need a checkbox as suggested you will need to insert a checkbox on the sheet and then right click on said checkbox and select View code.
Then paste the code provided by antialias...less the first and last line !
Code:
    Dim MyNumber As Integer
    
    'Make G2 Value Only / No Formula
         with Range("G2")
            .Value = .Value
        end with
    'Ask for a number to place into Cell E2:
        MyNumber = Application.InputBox("What Number do you want to enter into ""Cell E2""?")
        'If User Hits Cancel, Or doesn't enter anything:
        If MyNumber = False Then
            MsgBox "User Cancelled"
            Exit Sub
        End If

    'Place the desired number into Cell E2
        Range("E2").Value = MyNumber
 
Upvote 0

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