Increase decrease

nmh7

New Member
Joined
Jul 19, 2021
Messages
44
Office Version
  1. 365
Platform
  1. Windows
Hi!
I am currently trying to add an increase and decrease button to my excel sheet. I know how to add the button and link it to a certain cell. I was wondering if there is a way to only have one set of buttons for the entire sheet but only increase or decrease the value of the cell I select without changing the others.
 
Try this version then:
VBA Code:
Sub MyMacro()

    Dim x As String
    Dim y As Long
  
    On Error GoTo err_chk
    x = InputBox("Do you wish to (I)ncrease or (D)ecrease the value?")
    y = InputBox("How much do you wish to increase/decrease by?")
  
    Select Case UCase(x)
        Case "I"
            ActiveCell = ActiveCell + y
        Case "D"
            ActiveCell = ActiveCell - y
        Case Else
            MsgBox "You did not make a valid increase/decrease selection.", vbOKOnly
    End Select
  
    On Error GoTo 0
    Exit Sub
  
  
err_chk:
    If Err.Number = 13 Then
        MsgBox "You have not entered a valid number", vbOKOnly
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If
      
End Sub
Hi Joe I was wondering if there is a way to have two separate buttons where one is for increase and one is for decrease. And they ask how many you want to use or add based on the button clicked. I know this requires 2 macros but I think it will be easier to use.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Hi Joe I was wondering if there is a way to have two separate buttons where one is for increase and one is for decrease. And they ask how many you want to use or add based on the button clicked.
Sure, you already have all the code you need in my post. Just remove what you don't need for each one (don't be afraid to try some of these things out for yourself, it is a great way to learn!).
VBA Code:
Sub MyIncrease()

    Dim y As Long
   
    On Error GoTo err_chk
    y = InputBox("How much do you wish to increase by?")
   
    ActiveCell = ActiveCell + y
   
    On Error GoTo 0
    Exit Sub
   
   
err_chk:
    If Err.Number = 13 Then
        MsgBox "You have not entered a valid number", vbOKOnly
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If
       
End Sub

VBA Code:
Sub MyDecrease()

    Dim y As Long
   
    On Error GoTo err_chk
    y = InputBox("How much do you wish to decrease by?")
   
    ActiveCell = ActiveCell - y
   
    On Error GoTo 0
    Exit Sub
   
   
err_chk:
    If Err.Number = 13 Then
        MsgBox "You have not entered a valid number", vbOKOnly
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If
       
End Sub
 
Upvote 0
Solution
Sure, you already have all the code you need in my post. Just remove what you don't need for each one (don't be afraid to try some of these things out for yourself, it is a great way to learn!).
VBA Code:
Sub MyIncrease()

    Dim y As Long
  
    On Error GoTo err_chk
    y = InputBox("How much do you wish to increase by?")
  
    ActiveCell = ActiveCell + y
  
    On Error GoTo 0
    Exit Sub
  
  
err_chk:
    If Err.Number = 13 Then
        MsgBox "You have not entered a valid number", vbOKOnly
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If
      
End Sub

VBA Code:
Sub MyDecrease()

    Dim y As Long
  
    On Error GoTo err_chk
    y = InputBox("How much do you wish to decrease by?")
  
    ActiveCell = ActiveCell - y
  
    On Error GoTo 0
    Exit Sub
  
  
err_chk:
    If Err.Number = 13 Then
        MsgBox "You have not entered a valid number", vbOKOnly
    Else
        MsgBox Err.Number & ":" & Err.Description
    End If
      
End Sub
This is my last question I promise. Is there a way I can add to the code so It only selects from a certain column if I select the entire row. For example If I click on the row 7 I want only the value In column K7 to change while the rest of the row stays the same.
 
Upvote 0
If you change this line:
VBA Code:
    ActiveCell = ActiveCell + y
to this:
VBA Code:
    Cells(ActiveCell.Row, "K") = Cells(ActiveCell.Row, "K") + y
then it will always update column K of whatever row you are in.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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