Form UNLOAD issue on error

jvoss

Board Regular
Joined
Jun 13, 2015
Messages
76
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Good day all. I have a snipit of code that is on the usersform1 code sheet that runs on initialization of usersform1. However when it errors on <> "Blank" (in Sheet1 row x : cell H) the userform1 loads with the values in "Properties, Appearance, Value" (used this to debug). (not sure if this is the right wording)

VBA Code:
Sub Initialization_Form

Dim emptyRow As Long

'selects active sheet for checking if row x is ready.
     Sheet1.Activate

'Determine emptyRow
     emptyRow = WorksheetFunction.CountA(Range("i:i")) + 1 '<---------used to find first unused row in column i

'verify "blank" in first unused row, cell h

'MsgBox Sheets(1).Cells(emptyRow, 8).Text      '<---------debugging Msgbox

'On Error Resume Next ' <---------debugging statement will set once below issue is fixed.

     If Sheets(1).Cells(emptyRow, 8).Text = "Blank" Then '<---------check to see if next row has "Blank" in the "H" cell

     TextBox4 = "Blank" '<---------put this in the TextBox4 if row is "Blank"

     Else: '<---------if cell H is not "Blank"  show message and stop intiliziation and unload (me)
     MsgBox "There seems to be an error" & Sheets(1).Cells(emptyRow, 8).Text & " is not ready.", 16, "DATA ERROR"
     Unload (UserForm1) '<-----------------------------   this is the issue.  if this is not in the userform1 shows up after the sub exits
     Exit Sub
     MsgBox "sub exited", 16, "Fix Error"  '<--------------Debugging MsgBox

     End If
'rest of code to set all text boxs to ""
'as apposed to what is in the "Properties, Appearance, Value" (debugging)

End Sub


thanks in advance for the help.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi there

What happens if you change
VBA Code:
Unload (UserForm1)
to
VBA Code:
Unload UserForm1
 
Upvote 0
Hi there

What happens if you change
VBA Code:
Unload (UserForm1)
to
VBA Code:
Unload UserForm1
same results with either way. when dose the unload or show of table happen in the stack...
 

Attachments

  • excel feedback.jpg
    excel feedback.jpg
    24.3 KB · Views: 5
Upvote 0
when running this way
VBA Code:
Unload UserForm1

the code steps through and stops on
Exit Sub with a Runtime error 91
Object variable or with block variable not set

this sub is setup as Private Sub will that effect the Exit Sub statement?
 
Upvote 0
Problem is resolved. the error is/was caused by the original call for the form to show.
Since during the stack this call was never finished and the IF/THEN statement erred..

more information: by step.
step1 user activitates button to show USERFORM
step2 USERFORM is Initialized.
step3a userform call for check rows
step3b check row is good then Userform initialization form completed and step4
step3c if check row errors then sub is exited
step3d show userform request errors out and with ON ERROR RESUME NEXT set it ends sub
step4 show USERFORM is completed.
 
Upvote 0
Solution

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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