Calling Public Subroutine in userform Excel VBA - vba

I recently started to learn excel vba and at the moment I am stuck calling Public Subroutine from a userform Excel VBA. I have been trying to put the subroutine into a module and few other places but still it gives me an error.(Sub or Function not defined!)
Can you please guide in the right direction.
The function itself in module1
Public Sub Check(j As Integer)
If Worksheets("VBA").Cells(j, 19).Value = "Y" Then
imgA.Visible = True
imgB.Visible = False
imgC.Visible = False
imgD.Visible = False
ElseIf Worksheets("VBA").Cells(j, 19).Value = "N" Then
imgA.Visible = False
imgB.Visible = True
imgC.Visible = False
imgD.Visible = False
ElseIf Worksheets("VBA").Cells(j, 19).Value = "X" Then
imgA.Visible = False
imgB.Visible = False
imgC.Visible = True
imgD.Visible = False
ElseIf Worksheets("VBA").Cells(j, 19).Value = "F" Then
imgA.Visible = False
imgB.Visible = False
imgC.Visible = False
imgD.Visible = True
End If
End Sub
Here I am calling it in a userform
Private Sub UserForm_Initialize()
Call Check(i)
End Sub

Not intended as an answer to your current problem. Just a suggestion:
Public Sub Check(j As Integer)
Dim v
v = Worksheets("VBA").Cells(j, 19).Value
imgA.Visible = (v = "Y")
imgB.Visible = (v = "N")
imgC.Visible = (v = "X")
imgD.Visible = (v = "F")
End Sub

Related

Checking more than one condition and storing values

I have a problem that is driving me nuts. It should be straightforward, because I have done it many times before, but for some odd reason it is not working now...
Background
I am doing a few checks on some columns. If a value in each of the columns is found to be True, then boolean markers will be switched to False.
There are 3x columns to check and 3x boolean markers.
At the end, I check status of these boolean markers and get an output.
Code
Dim TfPCheck as boolean
Dim CentreV as boolean
Dim FlaggedTasks as boolean
Dim AddtionalInfoCheck As Boolean
TfPCheck= True
CentreV = True
FlaggedTasks = True
AdditionalInfoCheck = True
With Worksheets("Admin")
For i = 7 To LR
If .Cells(i, 12) = "True" Then
TfPCheck = False
Exit For
End If
Next i
End With
With Worksheets("Admin")
For i = 7 To LR
If .Cells(i, 14) = "True" Then
CentreV = False
Exit For
End If
Next i
End With
With Worksheets("Admin")
For i = 7 To LR
If .Cells(i, 16) = "True" Then
FlaggedTasks = False
Exit For
End If
Next i
End With
If TfPCheck = True And CentreV = True And FlaggedTasks = True Then
AdditionalInfoCheck = True
ElseIf TfPCheck = False And CentreV = True And FlaggedTasks = True Then
addtionalInfoCheck = False
ElseIf TfPCheck = True And CentreV = False And FlaggedTasks = True Then
addtionalInfoCheck = False
ElseIf TfPCheck = True And CentreV = True And FlaggedTasks = False Then
addtionalInfoCheck = False
ElseIf TfPCheck = False And CentreV = True And FlaggedTasks = False Then
addtionalInfoCheck = False
ElseIf TfPCheck = False And CentreV = False And FlaggedTasks = True Then
addtionalInfoCheck = False
ElseIf TfPCheck = True And CentreV = False And FlaggedTasks = False Then
addtionalInfoCheck = False
ElseIf TfPCheck = False And CentreV = False And FlaggedTasks = False Then
addtionalInfoCheck = False
End If
MsgBox (AdditionalInfoCheck)
Am I doing something wrong? Because AddtionalInfoCheck comes back as True, when it shouldn't.
Thanks
I don't know if this is going to resolve your issue but it seems that all of your code can be boiled down to the following.
Dim TfPCheck As Boolean, CentreV As Boolean, FlaggedTasks As Boolean
Dim LR As Long, AdditionalInfoCheck As Boolean
With Worksheets("Admin")
LR = Application.Max(.Cells(.Rows.Count, "L").End(xlUp).Row, _
.Cells(.Rows.Count, "N").End(xlUp).Row, _
.Cells(.Rows.Count, "P").End(xlUp).Row)
TfPCheck = IsError(Application.Match(True, .Range(.Cells(7, "L"), .Cells(LR, "L")), 0))
CentreV = IsError(Application.Match(True, .Range(.Cells(7, "N"), .Cells(LR, "N")), 0))
FlaggedTasks = IsError(Application.Match(True, .Range(.Cells(7, "P"), .Cells(LR, "P")), 0))
End With
AdditionalInfoCheck = CBool(TfPCheck And CentreV And FlaggedTasks)
Use Option Explicit. AdditionalInfoCheck was spelled two different ways.

Looking for ways to simplify my code

I'm having trouble adding another function in that macro I used to activate or deactivate columns in a Excel Workbook we are using at work. I'm getting the Out of stack space error when running it just adding one of the following function.
Mostly, I've used an If( ;1;0) to manage the activation part and an If(;TRUE;FALSE) for the locked/unlocked part. The function I want to had is based on the same idea using a verification code to Clearcontents of a cell and locked it. If the verification code is false, then, I want the cell to be unlocked so the user can write the value. Here is the code line I want to had times 15 as already done for the locked, unlocked function.
If Range("AS16") = "Vrai" Then
Range("AA16").ClearContents
Range("AA16").Locked = True
Else:
Range("AA16").Locked = False
End If
Here is the code I'm using right now.
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect ("Francis")
Dim Cell As Range
Set Cell = ActiveCell
Application.ScreenUpdating = False
For Each cellule In Range("S50:X50")
If cellule.Value = "1" Then cellule.EntireColumn.Hidden = False
Next cellule
For Each cellule In Range("S50:X50")
If cellule.Value = "0" Then cellule.EntireColumn.Hidden = True
Next cellule
For Each cellule In Range("I50:J50")
If cellule.Value = "1" Then cellule.EntireColumn.Hidden = False
Next cellule
For Each cellule In Range("I50:J50")
If cellule.Value = "0" Then cellule.EntireColumn.Hidden = True
Next cellule
If Range("AR16") = "Vrai" Then
Range("K16").Locked = False
Range("O16").Locked = False
Else:
Range("K16").Locked = True
Range("O16").Locked = True
End If
If Range("AR18") = "Vrai" Then
Range("K18").Locked = False
Range("O18").Locked = False
Else:
Range("K18").Locked = True
Range("O18").Locked = True
End If
If Range("AR20") = "Vrai" Then
Range("K20").Locked = False
Range("O20").Locked = False
Else:
Range("K20").Locked = True
Range("O20").Locked = True
End If
If Range("AR22") = "Vrai" Then
Range("K22").Locked = False
Range("O22").Locked = False
Else:
Range("K22").Locked = True
Range("O22").Locked = True
End If
If Range("AR24") = "Vrai" Then
Range("K24").Locked = False
Range("O24").Locked = False
Else:
Range("K24").Locked = True
Range("O24").Locked = True
End If
If Range("AR26") = "Vrai" Then
Range("K26").Locked = False
Range("O26").Locked = False
Else:
Range("K26").Locked = True
Range("O26").Locked = True
End If
If Range("AR28") = "Vrai" Then
Range("K28").Locked = False
Range("O28").Locked = False
Else:
Range("K28").Locked = True
Range("O28").Locked = True
End If
If Range("AR30") = "Vrai" Then
Range("K30").Locked = False
Range("O30").Locked = False
Else:
Range("K30").Locked = True
Range("O30").Locked = True
End If
If Range("AR32") = "Vrai" Then
Range("K32").Locked = False
Range("O32").Locked = False
Else:
Range("K32").Locked = True
Range("O32").Locked = True
End If
If Range("AR34") = "Vrai" Then
Range("K34").Locked = False
Range("O34").Locked = False
Else:
Range("K34").Locked = True
Range("O34").Locked = True
End If
If Range("AR36") = "Vrai" Then
Range("K36").Locked = False
Range("O36").Locked = False
Else:
Range("K36").Locked = True
Range("O36").Locked = True
End If
If Range("AR38") = "Vrai" Then
Range("K38").Locked = False
Range("O38").Locked = False
Else:
Range("K38").Locked = True
Range("O38").Locked = True
End If
If Range("AR40") = "Vrai" Then
Range("K40").Locked = False
Range("O40").Locked = False
Else:
Range("K40").Locked = True
Range("O40").Locked = True
End If
If Range("AR42") = "Vrai" Then
Range("K42").Locked = False
Range("O42").Locked = False
Else:
Range("K42").Locked = True
Range("O42").Locked = True
End If
If Range("AR44") = "Vrai" Then
Range("K44").Locked = False
Range("O44").Locked = False
Else:
Range("K44").Locked = True
Range("O44").Locked = True
End If
Application.ScreenUpdating = True
Application.Goto Cell
'ActiveSheet.Protect Password:="Francis"
End Sub
Thanks a lot for your help.
Have a nice day!
You typically don't want to have performance-expensive code running in that specific handler. Worksheet_Change gets invoked every time a cell changes... and that includes changing a cell's Locked property value.
So that's how you run out of stack space: your handler is modifying cells' Locked state, which triggers the Worksheet_Change event, which modifies cells' Locked state, which triggers the Worksheet_Change event, which modifies cells' Locked state, which triggers the Worksheet_Change event, which... which eventually blows the call stack.
So prevent this accidental recursion, you need to prevent Excel from firing worksheet events when you're handling one:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo CleanFail
Application.EnableEvents = False
'do stuff
CleanExit:
Application.EnableEvents = True
Exit Sub
CleanFail:
'handle errors here...
Resume CleanExit
End Sub
As for simplifying the code, that's more of a mandate for Code Review Stack Exchange, once your code works as intended.
If any C# dev is reading this, this particular situation now has an up-for-grabs issue on Rubberduck's GitHub repository: #3109 Prevent accidental recursion in Worksheet_Change and Workbook_SheetChange handlers; once that inspection is implemented, Rubberduck will be able to warn you when you handle Worksheet_Change without disabling application events.
The Out of stack error is caused by the Change event, as noted by #Mat
Try this version which also turns the events off and on
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cellule As Range, r As Long, isVrai As Boolean
ActiveSheet.Unprotect "Francis"
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
For Each cellule In Union(Range("I50:J50"), Range("S50:X50"))
With cellule
Select Case .Value2
Case "1": .EntireColumn.Hidden = False
Case "0": .EntireColumn.Hidden = True
End Select
End With
Next
For r = 16 To 44 Step 2
isVrai = (Range("AR" & r).Value2 = "Vrai")
Range("K" & r).Locked = Not isVrai
Range("O" & r).Locked = Not isVrai
If isVrai Then Range("AR" & r).ClearContents
Next
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
'ActiveSheet.Protect Password:="Francis"
End Sub
This section can be simplified:
For Each cellule In Range("S50:X50")
If cellule.Value = "1" Then cellule.EntireColumn.Hidden = False
Next cellule
For Each cellule In Range("S50:X50")
If cellule.Value = "0" Then cellule.EntireColumn.Hidden = True
Next cellule
For Each cellule In Range("I50:J50")
If cellule.Value = "1" Then cellule.EntireColumn.Hidden = False
Next cellule
For Each cellule In Range("I50:J50")
If cellule.Value = "0" Then cellule.EntireColumn.Hidden = True
Next cellule
To the following (however, note that this will unhide any non-zero values).
For Each cellule in Range("S50:X50")
cellule.EntireColumn.Hidden = (cellule.Value = "0")
Next
For Each cellule in Range("I50:J50")
cellule.EntireColumn.Hidden = (cellule.Value = "0")
Next
And this section:
If Range("AR16") = "Vrai" Then
Range("K16").Locked = False
Range("O16").Locked = False
Else:
Range("K16").Locked = True
Range("O16").Locked = True
End If
If Range("AR18") = "Vrai" Then
Range("K18").Locked = False
Range("O18").Locked = False
Else:
Range("K18").Locked = True
Range("O18").Locked = True
End If
....
Can be simplified using a loop over Range("AR16:AR44")
For Each cellule in Range("AR16:AR44") Step 2
cellule.Offset(,-33).Locked = (cellule.Value = "Vrai")
cellule.Offset(,-29).Locked = (cellule.Value = "Vrai")
Next

VB ComboBox Requires 2 Mouse Clicks to Select Index?

For some reason with this combobox I have in my code, when I run the program, it does not change the Selected Index with one mouse click. Instead, I have to select the drop down of the combo box again, and then select the index. Any ideas on what is going on here? Here is my code, I've tinkered with it for hours.
Public Class Form1
'Mod-level variable
Dim TransactionList As New List(Of Transaction)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = "Mike Smith's Bank Account"
Lb1.Visible = False
Lb2.Visible = False
Lb4.Visible = False
Tb1.Visible = False
Tb2.Visible = False
SubmitTransactionButton.Visible = False
TransactionListBox.Visible = False
End Sub
Private Sub Cb1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Cb1.SelectedIndexChanged
If Tb1.Text = "" Then
Tb1.Text = "0.00"
ElseIf Cb1.Text = "" Then
Lb4.Visible = False
LbAction.Visible = False
Lb1.Visible = False
Lb2.Visible = False
Tb1.Visible = False
Tb2.Visible = False
TransactionListBox.Visible = False
SubmitTransactionButton.Visible = False
ElseIf Cb1.Text = "Credit" Then
Lb4.Visible = False
LbAction.Visible = False
Lb1.Visible = True
Lb2.Visible = True
LbAction.Visible = False
Tb1.Visible = True
Tb2.Visible = True
TransactionListBox.Visible = False
Lb1.Text = "Enter Credit Amount"
Lb2.Text = "Describe the Income"
SubmitTransactionButton.Visible = True
ElseIf Cb1.Text = "Debit" Then
LbAction.Visible = False
Lb1.Visible = True
Lb4.Visible = False
Lb2.Visible = True
LbAction.Visible = False
Tb1.Visible = True
Tb2.Visible = True
TransactionListBox.Visible = False
Lb1.Text = "Enter Debit Amount"
Lb2.Text = "Describe the Expense"
SubmitTransactionButton.Visible = True
ElseIf Cb1.Text = "Display Transactions" Then
TransactionListBox.Visible = True
Lb4.Visible = False
LbAction.Visible = False
Lb1.Visible = False
Lb2.Visible = False
Tb1.Visible = False
Tb2.Visible = False
SubmitTransactionButton.Visible = False
For Each transaction In TransactionList
TransactionListBox.Items.Add(
String.Format("{0}: {1:C}. {2}",
transaction.Type,
transaction.Amount,
transaction.Description))
Next
ElseIf Cb1.Text = "Display Balance" Then
Lb4.Visible = True
Lb1.Visible = False
Lb2.Visible = False
LbAction.Visible = False
Tb1.Visible = False
Tb2.Visible = False
TransactionListBox.Visible = False
Lb4.Text = "Current Balance: $"
End If
End Sub
Private Sub SubmitTransactionButton_Click(sender As Object, e As EventArgs) Handles SubmitTransactionButton.Click
Dim transactionTypeString As String = Cb1.Text
Dim transactionDescriptionstring As String = Tb2.Text
Dim transactionAmountDecimal As Decimal
If Tb1.Text IsNot "" Then
'Tb1.Text = "0.00"
Tb2.Text = ""
Cb1.Text = ""
Lb1.Visible = False
Lb2.Visible = False
Tb1.Visible = False
Tb2.Visible = False
SubmitTransactionButton.Visible = False
End If
Try
transactionAmountDecimal = Decimal.Parse(Tb1.Text)
TransactionList.Add(New Transaction(
transactionTypeString,
transactionAmountDecimal,
transactionDescriptionstring))
Catch FormatExceptionParameter As FormatException
transactionAmountDecimal = 0D
End Try
End Sub
End Class
Public Class Transaction
Public Sub New(type As String, amount As Decimal, description As String)
Me.Type = type
Me.Amount = amount
Me.Description = description
If Me.Type = "Credit" Then
Me.Amount *= -1
End If
End Sub
Public Property Type As String
Public Property Amount As Decimal
Public Property Description As String
End Class

Word macro error - Runtime Error 4608, Value out of range

We have a macro we run to format the page for our publisher. There are several documents that use this macro. For smaller documents the macro runs without error, for larger documents we receive the error in the subject line of this thread.
Small document - <= 256KB
Large document - >= 500KB
For the documents that have the error I can open them in Word and manually make the settings without a problem.
Here is the second version of the macro
Function pagestuffB() As String
'
' Format for Publisher
'
'
Dim rv As String
rv = ""
On Error GoTo ErrorHndlr:
With Application
.Options.Pagination = False
.ScreenUpdating = False
With .ActiveDocument.PageSetup
.PaperSize = wdPaperLetter
' .PageWidth = InchesToPoints(8.5)
' .PageHeight = InchesToPoints(11)
.Orientation = wdOrientPortrait
.MirrorMargins = True 'ERROR HERE
.TopMargin = InchesToPoints(1.34)
.HeaderDistance = InchesToPoints(0.98)
.BottomMargin = InchesToPoints(1)
.FooterDistance = InchesToPoints(0.8)
.LeftMargin = InchesToPoints(1.61)
.RightMargin = InchesToPoints(1.4)
.Gutter = InchesToPoints(0)
.SectionStart = wdSectionContinuous
.OddAndEvenPagesHeaderFooter = True
.DifferentFirstPageHeaderFooter = True
.LineNumbering.Active = False
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
End With
pagestuffB = rv
Exit Function
ErrorHndlr:
If rv = "" Then
rv = "Macro error " & Err.Number
Select Case Err.Number
Case Else
End Select
End If
Resume Next
End Function
Version info: Word 2010, VS 2012.
I have the document that failed and will provide it if needed.
EDIT: The documents are here
This is the latest version of the macro, which actually runs, but.... It took .5 hours to format the two documents, two of the smallest, in the link above.
Function pagestuffB() As String
'
' Format for Publisher
'
'
Dim rv As String
rv = ""
On Error GoTo ErrorHndlr:
With Application
.Options.Pagination = False
.ScreenUpdating = False
.WindowState = wdWindowStateMinimize
End With
Dim oSec As Section
For Each oSec In Selection.Sections
With oSec.PageSetup
.Orientation = wdOrientPortrait 'moved per macropod
.PaperSize = wdPaperLetter
.MirrorMargins = True
.TopMargin = InchesToPoints(1.34)
.HeaderDistance = InchesToPoints(0.98)
.BottomMargin = InchesToPoints(1)
.FooterDistance = InchesToPoints(0.8)
.LeftMargin = InchesToPoints(1.61)
.RightMargin = InchesToPoints(1.4)
.Gutter = InchesToPoints(0)
.SectionStart = wdSectionContinuous
.OddAndEvenPagesHeaderFooter = True
.DifferentFirstPageHeaderFooter = True
.LineNumbering.Active = False
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
Next oSec
pagestuffB = rv
Exit Function
ErrorHndlr:
If rv = "" Then
rv = "Macro error " & Err.Number
Select Case Err.Number
Case Else
End Select
End If
Resume Next
End Function
So I removed these three lines of code and the macro worked very quickly on my computer for those two documents. It seems like you used a recorded macro to build this code. It's certainly hard to grasp what exactly you want this code to do since there are no comments describing what your code does :). Comment underneath if this suggestion does not fix your problem.
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1

Command Button Code stopped working

I was using this user form code yesterday and everything worked fine. Today, nothing is working. When my command button "Complete" is clicked, the code should verify that the user form is complete (Complete_Enter()) and then transfer the information from the userform to my worksheet. This all worked perfectly yesterday and today it does not. Instead when I click complete, VBA only runs the first line under the Complete_Enter() sub. Here is the code:
Private Sub ConnectorCoverProductionForm_Initialize()
'Empty Serial_NumberTextBox
Serial_Number.Value = ""
Serial_Number.SetFocus
'Empty Order_NumberTextBox
Order_Number.Value = ""
'Empty DateTextBox
TextBox1.Value = ""
Inspector.Clear
Assembler.Clear
Process_Code.Clear
'Uncheck OptionButton
OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
OptionButton4.Value = False
OptionButton5.Value = False
OptionButton6.Value = False
OptionButton21.Value = False
OptionButton12.Value = False
OptionButton13.Value = False
OptionButton14.Value = False
OptionButton15.Value = False
OptionButton16.Value = False
End Sub
Private Sub Assembler_DropButtonClick()
Assembler.List = Array("Trung", "Jesus", "Khoi", "Josie", "Omi")
End Sub
Private Sub ClearALL_Click()
Call ConnectorCoverProductionForm_Initialize
End Sub
Private Sub CommandButton1_Click()
Shell ("Explorer \\PC148\Assembly Group\Traveler
End Sub
Private Sub CommandButton2_Click()
Shell ("Explorer \\PC148\Assembly Group\Traveler
End Sub
Private Sub CommandButton3_Click()
Shell ("Explorer \\PC148\Assembly Group\Traveler Templates\Videos\Edited\Mag
End Sub
Private Sub CommandButton4_Click()
Shell ("Explorer \\PC148\Assembly Group\Traveler Templates\Videos\Edited\Mag
End Sub
Private Sub Complete_Click()
Dim emptyRow As Long
Sheet1.Activate
emptyRow = WorksheetFunction.CountA(Range("C:C")) + 1
Cells(emptyRow, 3).Value = Serial_Number.Value
Cells(emptyRow, 4).Value = Order_Number.Value
Cells(emptyRow, 5).Value = TextBox1.Value
Cells(emptyRow, 6).Value = Revision.Value
Cells(emptyRow, 7).Value = Inspector.Value
Cells(emptyRow, 8).Value = Assembler.Value
Cells(emptyRow, 9).Value = Process_Code.Value
If OptionButton1.Value = True Then Cells(emptyRow, 10).Value = OptionButton1.Caption
If OptionButton21.Value = True Then Cells(emptyRow, 10).Value = OptionButton21.Caption
If OptionButton2.Value = True Then Cells(emptyRow, 11).Value = OptionButton2.Caption
If OptionButton12.Value = True Then Cells(emptyRow, 11).Value = OptionButton12.Caption
If OptionButton3.Value = True Then Cells(emptyRow, 12).Value = OptionButton3.Caption
If OptionButton13.Value = True Then Cells(emptyRow, 12).Value = OptionButton13.Caption
If OptionButton4.Value = True Then Cells(emptyRow, 13).Value = OptionButton4.Caption
If OptionButton14.Value = True Then Cells(emptyRow, 13).Value = OptionButton14.Caption
If OptionButton5.Value = True Then Cells(emptyRow, 14).Value = OptionButton5.Caption
If OptionButton15.Value = True Then Cells(emptyRow, 14).Value = OptionButton15.Caption
If OptionButton6.Value = True Then Cells(emptyRow, 15).Value = OptionButton6.Caption
If OptionButton16.Value = True Then Cells(emptyRow, 15).Value = OptionButton16.Caption
End Sub
Private Sub Complete_Enter()
If Serial_Number.Value = "" Then MsgBox "Fill in Serial Number"
Exit Sub
If Order_Number.Value = "" Then MsgBox "Fill in Order Number"
Exit Sub
If TextBox1.Value = "" Then MsgBox "Fill in Date"
Exit Sub
If Revision.Value = "" Then MsgBox "Select the correct Revision"
Exit Sub
If Inspector.Value = "" Then MsgBox "Who was the inspector? If it was you,select 'SELF'"
Exit Sub
If Assembler.Value = "" Then MsgBox "Select Your Name as the Assembler"
Exit Sub
If Process_Code.Value = "" Then MsgBox "Select the correct Process Code"
Exit Sub
If OptionButton1.Value = False And OptionButton21.Value = False Then MsgBox "What is the Status of Step 1"
Exit Sub
If OptionButton2.Value = False And OptionButton12.Value = False Then MsgBox "What is the Status of Step 2"
Exit Sub
If OptionButton3.Value = False And OptionButton13.Value = False Then MsgBox "What is the Status of Step 3"
Exit Sub
If OptionButton4.Value = False And OptionButton14.Value = False Then MsgBox "What is the Status of Step 4"
Exit Sub
If OptionButton5.Value = False And OptionButton15.Value = False Then MsgBox "What is the Status of Step 5"
Exit Sub
If OptionButton6.Value = False And OptionButton16.Value = False Then MsgBox "What is the Status of Step 6"
Exit Sub
End Sub
Private Sub Inspector_DropButtonClick()
Inspector.List = Array("Tom", "Tre", "Omi", "Self")
End Sub
Private Sub Process_Code_DropButtonClick()
Process_Code.List = [index(12*(row(1:12)-1),)]
End Sub
Private Sub Revision_DropButtonClick()
Revision.List = [index(char(64+row(1:26)),)]
End Sub
I expect your routine should be modified like so:
Private Sub Complete_Enter()
If Serial_Number.Value = "" Then
MsgBox "Fill in Serial Number"
ElseIf Order_Number.Value = "" Then
MsgBox "Fill in Order Number"
ElseIf TextBox1.Value = "" Then
MsgBox "Fill in Date"
ElseIf Revision.Value = "" Then
MsgBox "Select the correct Revision"
ElseIf Inspector.Value = "" Then
MsgBox "Who was the inspector? If it was you,select 'SELF'"
ElseIf Assembler.Value = "" Then
MsgBox "Select Your Name as the Assembler"
ElseIf Process_Code.Value = "" Then
MsgBox "Select the correct Process Code"
ElseIf OptionButton1.Value = False And OptionButton21.Value = False Then
MsgBox "What is the Status of Step 1"
ElseIf OptionButton2.Value = False And OptionButton12.Value = False Then
MsgBox "What is the Status of Step 2"
ElseIf OptionButton3.Value = False And OptionButton13.Value = False Then
MsgBox "What is the Status of Step 3"
ElseIf OptionButton4.Value = False And OptionButton14.Value = False Then
MsgBox "What is the Status of Step 4"
ElseIf OptionButton5.Value = False And OptionButton15.Value = False Then
MsgBox "What is the Status of Step 5"
ElseIf OptionButton6.Value = False And OptionButton16.Value = False Then
MsgBox "What is the Status of Step 6"
End If
End Sub