I need some help with this vba code

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a spreadsheet and part of the code contains the following :

Code:
    Worksheets("home").Unprotect Password:="costings"
       If txtIncrease.Value = True Then
            If Worksheets("home").Range("E5").Value = "Activities" Then
                Worksheets("home").Range("X5").Value = "1"
            Else
                Worksheets("home").Range("X5").Value = "1.1"
       Else
            Worksheets("home").Range("X5").Value = "1"
       End If
       End If
    Worksheets("home").Protect Password:="costings"

The code is attached to a checkbox. There is a drop down box in E5 and if Activities is selected I need X5 to be a 1 regardless of if the checkbox is selected but if something other than Activities is selected, I want the checkbox (txtIncrease) to allow the control of X5. Meaning X5 needs to have a 1.1 and if it is selected or a 1 if it isn't selected.

Can someone help me with the vba code as I don't know much vba?

txtincrease is a checkbox. I know I should of called it chkIncrease but I didn't and now there is too many references to it to go and change it, both in vba and excel itself.



Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

What kind of checkbox are you using ...?

Is it an ActiveX one or a Form Control ..?
 
Upvote 0
Hi again,

If you are using an ActiveX object with your variable declared As CheckBox

Code:
Sub Test5()
[B]Dim txtIncrease As CheckBox[/B]
   Worksheets("home").Unprotect Password:="costings"
       If Worksheets("home").txtIncrease.Value = True And Worksheets("home").Range("E5").Value = "Activities" Then
          Worksheets("home").Range("X5").Value = "1"
       Else
          Worksheets("home").Range("X5").Value = "1.1"
       End If  
    Worksheets("home").Protect Password:="costings"
End Sub

HTH
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

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