Error 91 Variable Not Defined

Denny57

Board Regular
Joined
Nov 23, 2015
Messages
185
Office Version
  1. 365
Platform
  1. Windows
I have a number of UserForms into which I have added the "Call" command into the UserForm_Initialize() instruction. This has worked on all in my workbook except for the last one which returns the Error 91 message.

VBA Code:
Option Explicit

Dim ws As Worksheet
Private Sub userForm_Initialize()

        'Call cmdCallRecords_Click
        Set ws = Sheets("Draw Totals & Online Account")

End Sub
Private Sub cmdCallRecords_Click()

I have checked all the code and when the call command is run using the command button ('Call cmdCallRecords_Click deactivated as above) the form populates as expected.
However, whe the call line is activated as below, I get the error 91 message. The code does not contain any "With" blocks.

VBA Code:
Option Explicit

Dim ws As Worksheet
Private Sub userForm_Initialize()

        Call cmdCallRecords_Click
        Set ws = Sheets("Draw Totals & Online Account")

End Sub
Private Sub cmdCallRecords_Click()

I cannot understand why this might be when this syntax works perfectlly fine for many other userforms in the workbook.
FYI There is no complex code just direct mapping from cells on a single worksheet to corresponding cells on the UserForm.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
At the beginning of your code I can see that you have the Option Explicit statement, it means that you must declare all your variables, the error says "Variable Not Defined", so check that you have all the variables declared, even check that all the command names are correct written and that all your procedures exist.

You missed putting all the procedure code: cmdCallRecords_Click
 
Upvote 0
I have a number of UserForms into which I have added the "Call" command into the UserForm_Initialize() instruction. This has worked on all in my workbook except for the last one which returns the Error 91 message.

VBA Code:
Option Explicit

Dim ws As Worksheet
Private Sub userForm_Initialize()

        'Call cmdCallRecords_Click
        Set ws = Sheets("Draw Totals & Online Account")

End Sub
Private Sub cmdCallRecords_Click()

I have checked all the code and when the call command is run using the command button ('Call cmdCallRecords_Click deactivated as above) the form populates as expected.
However, whe the call line is activated as below, I get the error 91 message. The code does not contain any "With" blocks.

VBA Code:
Option Explicit

Dim ws As Worksheet
Private Sub userForm_Initialize()

        Call cmdCallRecords_Click
        Set ws = Sheets("Draw Totals & Online Account")

End Sub
Private Sub cmdCallRecords_Click()

I cannot understand why this might be when this syntax works perfectlly fine for many other userforms in the workbook.
FYI There is no complex code just direct mapping from cells on a single worksheet to corresponding cells on the UserForm.
Resolved..
Apparently had the instructions in UserForm-Initialize in the wrong order
 
Upvote 0
Solution

Forum statistics

Threads
1,215,465
Messages
6,124,980
Members
449,201
Latest member
Lunzwe73

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