subscript out of range when I reference a valid UserForm

Roland Hoelscher

New Member
Joined
Oct 15, 2022
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Sometimes when I reference a UserForm in my VBA code I get error message "Subscript Out of range". The UserForm which is referenced clearly exists; so I don't understand what is wrong with my code.
Here is a code snippet where I get the error "Subscript out of range". When I click on "Debug" the error points to the code line at the end "frmSelectFolder.show".
Can you help me understand what I'm doing wrong.
Thank you

Sub StartSummaryFile()
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'=== Module Name : ===
'=== Date Created : ===
'=== Author : Roland Hoelscher ===
'=== Summary Description : ===
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'
Application.ScreenUpdating = False
'
strVbaWorkbookName = Worksheets("SETTINGS").Cells(4, 3).Value
'
strDetailedLoggingYesNo = ThisWorkbook.Worksheets("SETTINGS").Cells(6, 3).Value
strSummaryFileName = ThisWorkbook.Worksheets("SETTINGS").Cells(8, 3).Value
strSummaryWorkbookName = Left(strSummaryFileName, Len(strSummaryFileName) - 5)
strDefaultFolder = ThisWorkbook.Worksheets("SETTINGS").Cells(7, 3).Value
'
lngTotalNumberOfRecords = 0
strModuleRef = "Create Summary File"
'
strLogMessageText = "Program started (" & Application.UserName & ")"
strLogMessageType = "N"
WriteLogRecord
'
frmProgress.Show vbModeless
frmProgress.lblProgress.Width = 1
frmProgress.lblProgress.Visible = True
frmProgress.Repaint
'
frmSelectFolder.Show
'
End Sub


1729008776049.png
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
The UserForm which is referenced clearly exists
When the userform does not exist, the message is similar to: "undefined variable"

The problem may be in the code you have in the usrform, when you open the usrform, you probably have code in the initialize or activate events, and that is where you possibly have a problem.
Run your code in debug mode, pressing F8, to enter the userform and see what the problem is.
Also put your userform code here to review it.

🧙‍♂️
 
Upvote 0
Solution
Hello Dante and thank you very much. I've copied the code from the UserForm initialize routine below; but you've solved my problem. There was an instruction in that initialize routine which caused the abend. The wording "Subscript out of range" was confusing to me. But I fixed the line of code which caused the error message and all is well.
Thanks again

Private Sub UserForm_initialize()
' set up SETTINGS variables
strDetailedLoggingYesNo = ThisWorkbook.Worksheets("SETTINGS").Cells(6, 3).Value
strSummaryFileName = ThisWorkbook.Worksheets("SETTINGS").Cells(8, 3).Value
strSummaryWorkbookName = Left(strSummaryFileName, Len(strSummaryFileName) - 5)
'
' initialize public variables
intNotificationMessageCount = 0
intWarningMessageCount = 0
intErrorMessageCount = 0
'

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,157
Messages
6,170,419
Members
452,325
Latest member
BlahQz

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