Hello Lakshmi Polisetti,
Welcome to Microsoft Q&A Forum.
From your description, I can understand that you are having a shift selection mechanism not working reliably, and because the code uses broad error suppression, so you don't see what is going wrong or where.
Here is a version of VBA code that you can kindly try
Put this in ThisWorkBook:
Option Explicit
Private Sub Workbook_Open()
On Error GoTo ErrHandler
Dim wsChecklist As Worksheet
Dim wsSettings As Worksheet
Dim s As String
Dim needPick As Boolean
Dim okPick As Boolean
'--- Get references
Set wsChecklist = GetSheet("Checklist")
Set wsSettings = GetSheet("Settings")
If wsChecklist Is Nothing Or wsSettings Is Nothing Then
MsgBox "Missing 'Checklist' or 'Settings' sheet.", vbExclamation
Exit Sub
End If
'--- Activate Checklist and clear previous value
wsChecklist.Activate
wsSettings.Range("B2").ClearContents
'--- Ask user for shift if not filled
needPick = (Trim$(CStr(wsSettings.Range("B2").Value)) = "")
If needPick Then
If MsgBox("No shift selected. Do you want to pick it now?", vbYesNo + vbQuestion, "Shift Selection") = vbYes Then
okPick = EnsureShiftSelected(wsSettings)
If Not okPick Then
MsgBox "No shift selected. Please try again later.", vbExclamation
End If
End If
End If
'--- Format and confirm if valid
If IsDate(wsSettings.Range("B2").Value) Then
wsSettings.Range("B2").NumberFormatLocal = "h:mm AM/PM"
s = Trim$(wsSettings.Range("B2").Text)
If Len(s) > 0 Then
MsgBox "Selected Shift: " & s, vbInformation, "Shift Confirmed"
End If
End If
'--- Run timers safely
RunSafe "InitTimer"
RunSafe "LoadQueueCategoryMap"
RunSafe "StartTimer", "Ideal Time"
Exit Sub
'--- Error handler
ErrHandler:
MsgBox "Error: " & Err.Description, vbCritical, "Workbook_Open"
End Sub
Add this in a regular module:
Option Explicit
'--- Helper: safely get sheet
Public Function GetSheet(name As String) As Worksheet
On Error Resume Next
Set GetSheet = ThisWorkbook.Worksheets(name)
On Error GoTo 0
End Function
'--- Helper: safely run a macro
Public Sub RunSafe(ByVal procName As String, Optional ByVal arg As Variant)
On Error Resume Next
If IsMissing(arg) Then
Application.Run procName
Else
Application.Run procName, arg
End If
If Err.Number <> 0 Then
Debug.Print "RunSafe failed: " & procName & " - " & Err.Description
Err.Clear
End If
On Error GoTo 0
End Sub
'--- Shift selection logic
Public Function EnsureShiftSelected(ByVal wsSettings As Worksheet) As Boolean
On Error GoTo Fallback
'Try running module method if exists
Dim v As Variant
v = Application.Run("modShiftPicker.EnsureShiftSelected")
If VarType(v) = vbBoolean And v = True Then
EnsureShiftSelected = (Trim$(CStr(wsSettings.Range("B2").Value)) <> "")
Exit Function
End If
Fallback:
'Fallback: simple input box (works even if mod not present)
Dim userShift As String
userShift = InputBox("Enter your shift (e.g. Morning / Afternoon / Night):", "Shift Picker")
If Len(Trim$(userShift)) > 0 Then
wsSettings.Range("B2").Value = userShift
EnsureShiftSelected = True
Else
EnsureShiftSelected = False
End If
End Function
Please let me know if you need any further assistance.
Hope you have a great day.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.