asked on
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' unable to update SubmittedDate, DateAccepted2 or Comments2 because no eBill has been generated
If Target.CountLarge > 1 Then Exit Sub
If (Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15) And Target.Row > 7 Then
If Cells(Target.Row, "F") = "" And Len(Cells(Target.Row, "A")) <> 0 Then
MsgBox "You cannot update SubmittedDate, DateAccepted2 or Comments2 because this Invoice has not had an eBill file generated yet.", vbExclamation, "InvElecHistoryID Missing!"
ActiveCell.Clear
ActiveCell.Offset(1).Select
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
' unable to update SubmittedDate, DateAccepted2 or Comments2 because no eBill has been generated
If Target.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
If (Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15) And Target.Row > 7 Then
If Cells(Target.Row, "F") = "" And Len(Cells(Target.Row, "A")) <> 0 Then
MsgBox "You cannot update SubmittedDate, DateAccepted2 or Comments2 because this Invoice has not had an eBill file generated yet.", vbExclamation, "InvElecHistoryID Missing!"
Target.Clear
Target.Offset(1).Select
End If
End If
Application.EnableEvents = True
End Sub
ASKER
Private Sub Worksheet_Change(ByVal Target As Range)
' unable to update SubmittedDate, DateAccepted2 or Comments2 because no eBill has been generated
If Target.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
If (Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15) And Target.Row > 7 Then
If Cells(Target.Row, "F") = "" And Len(Cells(Target.Row, "A")) <> 0 Then
MsgBox "You cannot update SubmittedDate, DateAccepted2 or Comments2 because this Invoice has not had an eBill file generated yet.", vbExclamation, "InvElecHistoryID Missing!"
Target.Clear
Target.Offset(1).Select
End If
End If
Application.EnableEvents = True
' check to see if the DateAccepted2 is prior to the SubmittedDate
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Target.Column = 14 And Target.Row > 1 Then
If Target <> "" Then
If Target.Offset(0, -1) = "" Then
Target = ""
Application.EnableEvents = True
Exit Sub
End If
If Not IsDate(Target) Then
Application.EnableEvents = True
Exit Sub
Else
If Target < Target.Offset(0, -1) Then
MsgBox "DateAccepted cannot be prior to the SubmittedDate.", vbExclamation, "Incorrect Date!"
Target = ""
Target.Select
Application.EnableEvents = True
Exit Sub
End If
End If
End If
End If
Application.EnableEvents = True
End Sub
Thanks,Private Sub Worksheet_Change(ByVal Target As Range)
' unable to update SubmittedDate, DateAccepted2 or Comments2 because no eBill has been generated
If Target.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
If (Target.Column = 13 Or Target.Column = 15) And Target.Row > 7 Then
If Cells(Target.Row, "F") = "" And Len(Cells(Target.Row, "A")) <> 0 Then
MsgBox "You cannot update SubmittedDate, DateAccepted2 or Comments2 because this Invoice has not had an eBill file generated yet.", vbExclamation, "InvElecHistoryID Missing!"
Target.Clear
Target.Offset(1).Select
End If
' check to see if the DateAccepted2 is prior to the SubmittedDate
ElseIf Target.Column = 14 And Target.Row > 7 Then
If Target <> "" Then
If Target.Offset(0, -1) = "" Then
Target = ""
Application.EnableEvents = True
Exit Sub
End If
If Not IsDate(Target) Then
Application.EnableEvents = True
Exit Sub
Else
If Target < Target.Offset(0, -1) Then
MsgBox "DateAccepted cannot be prior to the SubmittedDate.", vbExclamation, "Incorrect Date!"
Target = ""
Target.Select
Application.EnableEvents = True
Exit Sub
End If
End If
End If
End If
Application.EnableEvents = True
End Sub
ASKER
Private Sub Worksheet_Change(ByVal Target As Range)
' unable to update SubmittedDate, DateAccepted2 or Comments2 because no eBill has been generated
If Target.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
If (Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15) And Target.Row > 7 Then
If Cells(Target.Row, "F") = "" And Len(Cells(Target.Row, "A")) <> 0 Then
MsgBox "You cannot update SubmittedDate, DateAccepted2 or Comments2 because this Invoice has not had an eBill file generated yet.", vbExclamation, "InvElecHistoryID Missing!"
Target.Clear
Target.Offset(1).Select
End If
End If
' check to see if the DateAccepted2 is prior to the SubmittedDate
If Target.Column = 14 And Target.Row > 7 Then
If Target <> "" Then
If Target.Offset(0, -1) = "" Then
Target = ""
Application.EnableEvents = True
Exit Sub
End If
If Not IsDate(Target) Then
Application.EnableEvents = True
Exit Sub
Else
If Target < Target.Offset(0, -1) Then
MsgBox "DateAccepted cannot be prior to the SubmittedDate.", vbExclamation, "Incorrect Date!"
Target = ""
Target.Select
Application.EnableEvents = True
Exit Sub
End If
End If
End If
End If
Application.EnableEvents = True
End Sub
ASKER
but then the Cell M13 and M14 become locked.What do you mean by that?
ASKER
Private Sub Worksheet_Change(ByVal Target As Range)
' unable to update SubmittedDate, DateAccepted2 or Comments2 because no eBill has been generated
If Target.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
If (Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15) And Target.Row > 7 Then
If Cells(Target.Row, "F") = "" And Len(Cells(Target.Row, "A")) <> 0 Then
MsgBox "You cannot update SubmittedDate, DateAccepted2 or Comments2 because this Invoice has not had an eBill file generated yet.", vbExclamation, "InvElecHistoryID Missing!"
Target.Clear
Target.Offset(1).Select
Application.EnableEvents = True
End If
End If
' check to see if the DateAccepted2 is prior to the SubmittedDate
If Target.Column = 14 And Target.Row > 7 Then
If Target <> "" Then
If Target.Offset(0, -1) = "" Then
Target = ""
Application.EnableEvents = True
Exit Sub
End If
If Not IsDate(Target) Then
Application.EnableEvents = True
Exit Sub
Else
If Target < Target.Offset(0, -1) Then
MsgBox "DateAccepted cannot be prior to the SubmittedDate.", vbExclamation, "Incorrect Date!"
Target = ""
Target.Select
Application.EnableEvents = True
Exit Sub
End If
End If
Target.Offset(0, 1).Select
End If
End If
Application.EnableEvents = True
End Sub
The REFRESH CODE
Private Sub cmdRefreshSQLData3ed_Click()
' RefresheBillDatafromSQLSP Macro
' RefresheBillDatafromSQLSP
'
Dim i As Long
Dim wb1 As Excel.Workbook
Dim k As Long
ActiveWorkbook.Worksheets("E-Bill Tracking").Activate
ActiveWorkbook.ActiveSheet.Unprotect Password:="eBillStatus"
i = 8
k = 2
Dim ctrl As CommandBarControl
Dim cb As CommandBar
Application.CommandBars(1).Controls("Tools").Controls("Protection").Enabled = False
' Warn user that existing data in Columns M, N and O will be deleted
YesNo = MsgBox("Any existing data in SubmittedDate, DateAccepted2 and Comments2 will be deleted. Do you wish to proceed?", vbYesNo + vbCritical, "WARNING!")
If YesNo = vbNo Then
Range("A8").Select
ActiveSheet.Protect
ActiveSheet.Protect AllowFiltering:=True
Exit Sub
Else
'remove any filters prior to refreshing the data
If ActiveWorkbook.ActiveSheet.FilterMode Or _
ActiveWorkbook.ActiveSheet.AutoFilterMode Then _
ActiveWorkbook.ActiveSheet.ShowAllData
Range("A8").Select
' Remove any existing data in Columns M, N and O
Do Until i > Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
If Cells(i, 13).Value <> "" Or Cells(i, 14).Value <> "" Or Cells(i, 15).Value <> "" Then
Cells(i, 13).Value = ""
Cells(i, 14).Value = ""
Cells(i, 15).Value = ""
k = k + 1
End If
i = i + 1
Loop
For Each objconnection In ThisWorkbook.Connections
'Get current background-refresh value
bBackground = objconnection.OLEDBConnection.BackgroundQuery
'Temporarily disable background-refresh
objconnection.OLEDBConnection.BackgroundQuery = False
'Refresh this connection
objconnection.Refresh
'Set background-refresh value back to original value
objconnection.OLEDBConnection.BackgroundQuery = bBackground
Next
End If
Range("L8").Select
ActiveWorkbook.ActiveSheet.Protect
ActiveSheet.Protect AllowFiltering:=True
End Sub
ASKER
' unable to update SubmittedDate, DateAccepted2 or Comments2 because no eBill has been generated
If Target.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
If (Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15) And Target.Row > 7 Then
If Cells(Target.Row, "F") = "" And Len(Cells(Target.Row, "A")) <> 0 Then
MsgBox "You cannot update SubmittedDate, DateAccepted2 or Comments2 because this Invoice has not had an eBill file generated yet.", vbExclamation, "InvElecHistoryID Missing!"
Target.Clear
Target.Offset(1).Select
Application.EnableEvents = True
End If
End If
ASKER
ASKER
Private Sub Worksheet_Change(ByVal Target As Range)
' unable to update SubmittedDate, DateAccepted2 or Comments2 because no eBill has been generated
If Target.CountLarge > 1 Then Exit Sub
Application.EnableEvents = False
If (Target.Column = 13 Or Target.Column = 14 Or Target.Column = 15) And Target.Row > 7 Then
If Cells(Target.Row, "F") = "" And Len(Cells(Target.Row, "A")) <> 0 Then
MsgBox "You cannot update SubmittedDate, DateAccepted2 or Comments2 because this Invoice has not had an eBill file generated yet.", vbExclamation, "InvElecHistoryID Missing!"
Target.Clear
Target.Offset(1).Select
Application.EnableEvents = True
End If
End If
' check to see if the DateAccepted2 is prior to the SubmittedDate
If Target.Column = 14 And Target.Row > 7 Then
If Target <> "" Then
If Target.Offset(0, -1) = "" Then
Target = ""
Application.EnableEvents = True
Exit Sub
End If
If Not IsDate(Target) Then
Application.EnableEvents = True
Exit Sub
Else
If Target < Target.Offset(0, -1) Then
MsgBox "DateAccepted cannot be prior to the SubmittedDate.", vbExclamation, "Incorrect Date!"
Target = ""
Target.Select
Application.EnableEvents = True
Exit Sub
End If
End If
Target.Offset(0, 1).Select
End If
End If
Application.EnableEvents = True
End Sub
Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.
TRUSTED BY