Syntax for code to run on open

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this code that needs to run when the spreadsheet is opened. It is an excel table inserted using the insert - table function and I have a check box that is meant to add 10% on to the total of a row if it is needed.

Why won't it work?
Code:
Private Sub chkIncrease_Click()
If chkIncrease = True Then
    ListObjects("NPSS_quote").ListColumns("10%Increase").DataBodyRange.Value = "1.1"
Else
    ListObjects("NPSS_quote").ListColumns("10%Increase").DataBodyRange.Value = "1"
End If

End Sub

I currently have this code that works once the check box is selected. What it does is it puts a 1 or a 1.1 into a hidden field in the table for that row and the formula in the total cell is multiplied by this cell. It won't work until you select the check box for the first time. What do I do to put a default 1 into the cell on form load?

Thanks,
Dave
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hello,

In the module ThisWorkbook ... you could test following:

Code:
Private Sub Workbook_Open()
   Sheet1.CheckBoxes("chkIncrease").Value = True
End Sub

Hope this will help
 
Upvote 0
I got it to work with this code

Code:
    Sheets("NPSS_quote_sheet").ListObjects("NPSS_quote").ListColumns("10%Increase").DataBodyRange.Value = "1"
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,040
Members
449,063
Latest member
ak94

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