Change range of values in one command button click macro

DriedMangoes

New Member
Joined
Jun 3, 2018
Messages
3
Please be nice to me, I'm trying to learn VBA/macros by my own again after 15 years of not doing it :(

I know this is basic but huhuhu anyway.. I know how to change a value of a cell by a command button, but how do I change all of those values in one click of the command button. See my attached picture.

2eov7sx.jpg


So I want to change the values of A1:I11 to become less 5% of their original value by clicking the "LESS 5%" button, and by clicking "Original Value", they will return to the original value I placed.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
One way...

Code:
    Application.ScreenUpdating = False
    Range("K1").Value = "0.95"
    Range("K1").Copy
    Range("A1:I11").PasteSpecial Paste:=xlPasteAll, Operation:=xlMultiply
    With Application
        .CutCopyMode = False
        Range("K1").ClearContents
        .ScreenUpdating = True
    End With
 
Last edited:
Upvote 0
Another way
Code:
Sub Less5()
With Range("A1:I11")
   .Value = Evaluate(Replace("if(@<>"""",.95*@,"""")", "@", .Address))
End With
End Sub
 
Upvote 0
Wow I have never encountered this before, it worked, thank you! Would it be okay if I asked what "k1" stands for?
And also, is there a way for the values to return to its original value, say, if I clicked "LESS 5%", 900 would become 855, then if I clicked "ORIGINAL VALUE", 855 would go back to 900. Of course I cannot change "0.95" to "1.05" and create another command as it will only pile on top (as in 900*0.95*1.05).
 
Upvote 0
Hello Fluff, I am years behind with all these stuff so pardon me if I ask silly questions like.. do I replace @ with a range? and what do I put inside the quotation marks?

Another way
Code:
Sub Less5()
With Range("A1:I11")
   .Value = Evaluate(Replace("if(@<>"""",.95*@,"""")", "@", .Address))
End With
End Sub
 
Upvote 0
do I replace @ with a range? and what do I put inside the quotation marks?
No, you don't need to change anything. Just run it as-is.
 
Upvote 0
And to add return to the original value try
Code:
Sub Add5()
With Range("A1:I11")
   .Value = Evaluate(Replace("if(@<>"""",@/.95,"""")", "@", .Address))
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,616
Members
452,661
Latest member
Nonhle

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