LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Code to Implement Required Cells Not Working

I have a worksheet called "Change Request Form" where users are required to
input values in the following cells:

C9 = CPM Full Name
C10 = IT PM Full Name
C11 = Change Type
C12 = Reason Category
C13 = Project Name
C14 = Release
C15 = PAT ID
C16 = PRISM ID
C17 = Explanation
E15 = New PAT ID
E16 = New PRISM ID

I want to require users to provide input in most or all of the other
aforementioned cells prior to Saving the workbook depending on the value of
cell C11.

I wrote the code shown below and put it in the ThisWorkbook object.
Unfortunately, upon testing, users are still able to Save the workbook
without all the required cells being populated.

Being somewhat of a novice with VBA, I would be very grateful if someone
could tell me where I have gone wrong with my code.

Thanks in advance for any assistance.

Bob

-----------------------

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

' This code checks to see that all required fields contain
' data before allowing the user to Save the workbook

Dim iCell As Variant

' Change Type = blank

If Sheets("CTI Change Request Form").Range("C11").Value = "" Then
Cancel = True
MsgBox "The workbook cannot be saved until a Change Type has
been selected.", _
vbCritical, "Missing Change Type!"
Sheets("CTI Change Request Form").Range("C11").Select
Exit Sub
End If

' Reason Category = blank

If Sheets("CTI Change Request Form").Range("C12").Value = "" Then
Cancel = True
MsgBox "The workbook cannot be saved until a Reason Category has
been selected.", _
vbCritical, "Missing Reason Category!"
Sheets("CTI Change Request Form").Range("C12").Select
Exit Sub
End If

' Change Type = ADD

If Sheets("CTI Change Request Form").Range("C11").Value = "ADD" Then
For Each iCell In Sheets("CTI Change Request
Form").Range("C9:C11,C13:C16")
If IsEmpty(Sheets("CTI Change Request Form").Range(iCell.Address))
Then
Cancel = True
MsgBox "The workbook cannot be saved until ALL fields have been
populated.", _
vbCritical, "Missing Required Data!"
Exit Sub
End If
Next iCell
End If

' Change Type = MOVE

If Sheets("CTI Change Request Form").Range("C11").Value = "MOVE" Then
For Each iCell In Sheets("CTI Change Request Form").Range("C9:C17")
If IsEmpty(Sheets("CTI Change Request Form").Range(iCell.Address))
Then
Cancel = True
MsgBox "The workbook cannot be saved until ALL fields have been
populated.", _
vbCritical, "Missing Required Data!"
Exit Sub
End If
Next iCell
End If

' Change Type = DROP, ON HOLD, CANCEL, or RE-START

If Sheets("CTI Change Request Form").Range("C11").Value = "DROP" Or _
Sheets("CTI Change Request Form").Range("C11").Value = "ON HOLD" Or _
Sheets("CTI Change Request Form").Range("C11").Value = "CANCEL" Or _
Sheets("CTI Change Request Form").Range("C11").Value = "RE-START" Then
For Each iCell In Sheets("CTI Change Request
Form").Range("C9:C13,C15:C17")
If IsEmpty(Sheets("CTI Change Request Form").Range(iCell.Address))
Then
Cancel = True
MsgBox "The workbook cannot be saved until ALL fields have been
populated.", _
vbCritical, "Missing Required Data!"
Exit Sub
End If
Next iCell
End If

' Change Type = REF. CHANGE and Reason Category = PAT ID changed

If Sheets("CTI Change Request Form").Range("C11").Value = "REF. CHANGE" And _
Sheets("CTI Change Request Form").Range("C12").Value = "PAT ID changed"
Then
For Each iCell In Sheets("CTI Change Request
Form").Range("C9:C13,C15:C17,E15")
If IsEmpty(Sheets("CTI Change Request Form").Range(iCell.Address))
Then
Cancel = True
MsgBox "The workbook cannot be saved until ALL fields have been
populated.", _
vbCritical, "Missing Required Data!"
Exit Sub
End If
Next iCell
End If

' Change Type = REF. CHANGE and Reason Category = PRISM ID changed

If Sheets("CTI Change Request Form").Range("C11").Value = "REF. CHANGE" And _
Sheets("CTI Change Request Form").Range("C12").Value = "PRISM ID changed"
Then
For Each iCell In Sheets("CTI Change Request
Form").Range("C9:C13,C15:C17,E16")
If IsEmpty(Sheets("CTI Change Request Form").Range(iCell.Address))
Then
Cancel = True
MsgBox "The workbook cannot be saved until ALL fields have been
populated.", _
vbCritical, "Missing Required Data!"
Exit Sub
End If
Next iCell
End If

' Change Type = REF. CHANGE and Reason Category = PAT and PRISM IDs changed

If Sheets("CTI Change Request Form").Range("C11").Value = "REF. CHANGE" And _
Sheets("CTI Change Request Form").Range("C12").Value = "PAT and PRISM IDs
changed" Then
For Each iCell In Sheets("CTI Change Request
Form").Range("C9:C13,C15:C17,E15:E16")
If IsEmpty(Sheets("CTI Change Request Form").Range(iCell.Address))
Then
Cancel = True
MsgBox "The workbook cannot be saved until ALL fields have been
populated.", _
vbCritical, "Missing Required Data!"
Exit Sub
End If
Next iCell
End If

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
format cells as zip code not working SS Excel Discussion (Misc queries) 3 December 3rd 09 02:53 AM
implement vlookup formula to VBA code karlo via OfficeKB.com Excel Programming 1 February 25th 09 08:47 PM
Search cells code not working Phrank Excel Programming 8 September 7th 07 03:05 AM
Can you implement a custom format with VB code? pH7[_5_] Excel Programming 3 July 10th 04 07:41 AM
Using a collection class to implement mutliple find/replace strings in cells Bill Hertzing Excel Programming 2 February 18th 04 01:42 AM


All times are GMT +1. The time now is 04:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"