Toggle between 2 values in a cell

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,375
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a check box to increase a quote by 10%. The formula is multiplied by a cell that contains a 1 or 1.1, depending on whether the check box is selected. I have the following code that won't work, what is wrong with it and what is a more efficient way to write it?

Code:
Private Sub chkIncrease_Click()
    If ThisWorkbook.Worksheets("NPSS_quote_sheet").Cells(11, 13).Value = "1.1" Then
        ThisWorkbook.Worksheets("NPSS_quote_sheet").Cells(11, 13).Value = "1"
        Else
        ThisWorkbook.Worksheets("NPSS_quote_sheet").Cells(11, 13).Value = "1.1"
    End If
End Sub

Thanks,
Dave
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Now I am trying to get just the first part of this code working and I get the error of application defined or object error.

Code:
Private Sub chkIncrease_Click()
    If chkIncrease.Value = "True" Then
        Range("M11").Value = "1.1"
    Else
        'Worksheets("NPSS_quote_sheet").Range("M11").Value = "1"
    End If
End Sub

Can someone help me debug this code please?
 
Upvote 0
Got it working with this code:

Code:
If Worksheets("NPSS_quote_sheet").Range("M11").Value = "1.1" Then
        Worksheets("NPSS_quote_sheet").Range("M11").Value = "1"
    Else
        Worksheets("NPSS_quote_sheet").Range("M11").Value = "1.1"
    End If
 
Last edited:
Upvote 0
Assuming M11 already contains either 1 or 1.2 you can also do it in a single line like this
Code:
Worksheets("NPSS_quote_sheet").Range("M11").Value = 2.1 - Worksheets("NPSS_quote_sheet").Range("M11").Value

.. or I would prefer
Code:
With Worksheets("NPSS_quote_sheet").Range("M11")
  .Value = 2.1 - .Value
End With


BTW, if you are putting numerical values into a cell, best not to enclose them in quote marks.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,189
Members
452,616
Latest member
intern444

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