jake.peterson
Board Regular
- Joined
- May 22, 2012
- Messages
- 68
I created a form to capture information for employee transitions. Based on the transition type I require certain fields to be completed. I run the same code on as many as 5 sheets in the same workbook(could be mroe in the future, I only built 5 for now).
What I want to do is cycle through the sheets BeforeSave and display a msgbox for each sheet that highlights any missing information and give the user the option to cancel the save process and edit or continue with an incomplete form. I use "G21" to determine if the sheet was used as all transitions hinge on the value in G21. Here's what I have so far:
So a few questions:
1) How can i cycle though a specified number(5 for now) of sheets in "for each ws in ThisWorkbook"?
2) What is the best way to compile the message for missing information?
Thank you for taking a look.
What I want to do is cycle through the sheets BeforeSave and display a msgbox for each sheet that highlights any missing information and give the user the option to cancel the save process and edit or continue with an incomplete form. I use "G21" to determine if the sheet was used as all transitions hinge on the value in G21. Here's what I have so far:
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim TType As String
Dim ws As Worksheet
Dim S_date, G_live, Candidate, Cube, Division, New_title, Role_change, LOA_date, Return_date, Term_date, Term_type, Notes As String
Dim msg As String
For Each ws In ThisWorkbook.Worksheets
'select sheet so user can view when msgbox pops
ws.Select
'check to see if sheet was used
If Range("g21") <> "" Then
TType = ws.Range("G21").Value
Select Case TType
Case "New Hire (ISR)"
If ws.Range("d27") = "" Then S_date = "Start Date with Inside Sales"
If ws.Range("d29") = "" Then G_live = "Go Live Date on Phone"
If ws.Range("d33") = "" Then Candidate = "Candidate Type"
If ws.Range("d35") = "" Then Cube = "Cube Location"
Case "New Hire with Territory (RIC)"
If ws.Range("d27") = "" Then Sdate = "Start Date with Inside Sales"
If ws.Range("d29") = "" Then G_live = "Go Live Date on Phone"
If ws.Range("d33") = "" Then Candidate = "Candidate Type"
If ws.Range("d39") = "" Then Division = "Inside Sales Division"
Case "Role Change with Territory(RIC)"
If ws.Range("d35") = "" Then Cube = "Cube Location"
If ws.Range("d39") = "" Then Division = "Inside Sales Division"
Case "Termination"
If ws.Range("i41") = "" Then Term_type = "Termination Type"
If ws.Range("i43") = "" Then Term_date = "Termination Date"
Case "Leave of Absense"
If ws.Range("i34") = "" Then LOA_date = "LOA Effective Date"
If ws.Range("i36") = "" Then Return_date = "Date of Expected Return"
Case "Other"
If ws.Range("c51") = "" Then Notes = "Manager Notes"
'msgbox list each missing piece of information
'ie "Missing Required Information:
' Start Date with inside sales
' Candidate Type
' Continue and save or cancel?
'set variables back to "" before next sheet
' S_date = ""
' G_live = ""
' Candidate = ""
' Cube = ""
' Division = ""
' New_title = ""
' Role_change = ""
' LOA_date = ""
' Return_date = ""
' Term_date = ""
' Term_type = ""
' Notes = ""
End Select
End If
Next ws
End Sub
So a few questions:
1) How can i cycle though a specified number(5 for now) of sheets in "for each ws in ThisWorkbook"?
2) What is the best way to compile the message for missing information?
Thank you for taking a look.