What is wrong with my code

Sweedler

Board Regular
Joined
Nov 13, 2020
Messages
114
Office Version
  1. 2016
Platform
  1. Windows
  2. MacOS
Hello

I have the following code for a VBA user form and something in it is the reason why my UserForm Box won't open.

VBA Code:
Private Sub lvSektioner_ItemCheck(ByVal Item As MSComctlLib.ListItem)
    Dim li As MSComctlLib.ListItem
    Dim lRad As Long
    Dim b As Boolean
    
    Application.Cursor = xlWait
    Application.ScreenUpdating = False
    
    b = IsSheetProtected(shNormal)
    If b Then
        shNormal.Unprotect "sb123"
    End If
    
    Set li = Item
    lRad = Mid(Item.Key, 4)
    
    If li.Checked Then
        VisaSektion True, lRad
    Else
        VisaSektion False, lRad
    End If
    
    If b Then
        shNormal.Protect "sb123"
    End If
    
    Application.ScreenUpdating = True
    Application.Cursor = xlDefault
    
End Sub

I am not sure where things are going wrong, but I wonder exactly what the "sb123" is in reference to.

Help please
 
Last edited by a moderator:

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Would be the password to unprotect your worksheet.

Is there a USerForm initialize code?
You were right regarding that. It is the password to unprotect the sheet. Cant believe I missed that one. Thank you.

Where would I find a UserForm initialize code?

Unfortunately I am still not able to run the USER FORM. The command button clicks fine, but it stops on this code.
 
Upvote 0
At what line does is highlited and is the userform supposed to show with this code?
 
Upvote 0
Well, the section highlighted in yellow is this:

Private Sub cmdSektioner_Click()

frmSektioner.Show

End Sub

Which is the code to simply show the UserForm.

But the title line of the code I posted in the original thread is highlighted Blue at the same time.
 
Upvote 0
I don't believe I do, certainly not among the code on this sheet.

I tried just removing those lines of code, but it had not effect.
 
Upvote 0
If the code stops here it most likely means you have problems in the Initialize/Activate event of the userform.
VBA Code:
frmSektioner.Show

To see the code in the Initialize/Activate event open the userform in Design mode and double click it.

That should lead you to the userform's code module and you can use the 2 dropdowns at the top to navigate through the code

Another thing you could do is change the Error Trapping level.

To do that go to Tools>Options... in the VBE and on the General tab select Break on All errors.

Once you've done that try opening the userform again.
 
Upvote 0

Forum statistics

Threads
1,215,617
Messages
6,125,867
Members
449,266
Latest member
davinroach

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