Sub or function not defined

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Whenever I open my spreadsheet I get a error, Sub or function not defined. This code is highlighted

Code:
Sub workbook_open()
    
    ActiveSheet.Unprotect Password:="services"
                ListObjects("Services").ListColumns("10%Increase").DataBodyRange.Value = "1"
    ActiveSheet.Protect Password:="services"

End Sub

The code just has to put a "1" in a column of a table as the formula in the total column relies on it. What do I have to define in this code to get it to work?
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try

Code:
[COLOR="#006400"]ActiveSheet[/COLOR].ListObjects("Services") .....
 
Upvote 0
Try

Code:
Sub workbook_open()
With ActiveSheet
  .Unprotect Password:="services"
  . ListObjects("Services").ListColumns("10%Increase").DataBodyRange.Value = "1"
   .Protect Password:="services"
end with
End Sub
 
Upvote 0
Try

Code:
Sub workbook_open()
With ActiveSheet
  .Unprotect Password:="services"
  . ListObjects("Services").ListColumns("10%Increase").DataBodyRange.Value = "1"
   .Protect Password:="services"
end with
End Sub

I get an error saying subscript out of range and it highlights the following code:

Code:
    .ListObjects("Services").ListColumns("10%Increase").DataBodyRange.Value = "1"
 
Upvote 0
Is the correct sheet being applied when the workbook opens ?
Is "Services" correct?
Is "10%Increase" correct ?
Syntax in all cases must be exact....case, spaces, etc !
 
Upvote 0
Thanks Michael,

Got it to work with this code:

Code:
Sub workbook_open()
With Worksheets("Services")
    .Unprotect Password:="services"
    .ListObjects("Services").ListColumns("10%Increase").DataBodyRange.Value = "1"
    .Protect Password:="services"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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