G'day,
I am not a VBA expert. I understand what I want excel and VBA to do for my projects, but I have very simple knowledge of how coding actually works. I get by by asking questions here, which you fine folk are so kind to assist with. I also rehash others VBA code that I stumble across and repurpose where possible.
My current need for help is around exiting a VBA when the cancel button is selected in an input box, or when the input box is left blank.
I have this problem for a couple of VBA's. I will present them all here. Feel free to help with any or all, or if there is a generic string I can add to each code that will work as required.
Thanks heaps for everyone's help on these boards. You help make people like me look good.
I am not a VBA expert. I understand what I want excel and VBA to do for my projects, but I have very simple knowledge of how coding actually works. I get by by asking questions here, which you fine folk are so kind to assist with. I also rehash others VBA code that I stumble across and repurpose where possible.
My current need for help is around exiting a VBA when the cancel button is selected in an input box, or when the input box is left blank.
I have this problem for a couple of VBA's. I will present them all here. Feel free to help with any or all, or if there is a generic string I can add to each code that will work as required.
Thanks heaps for everyone's help on these boards. You help make people like me look good.
VBA Code:
Sub ConfirmExt_click()
Selection.Interior.Color = RGB(215, 245, 215)
Dim sCmt As String
Dim rCell As Range
sCmt = InputBox( _
Prompt:="Have you confirmed this extra shift or extension with the DAO?" & vbCrLf & _
"Please add your name, date and time this was confirmed. ", _
Title:="Comment to Add")
If sCmt = "" Then
MsgBox "No details added. Please start again and include your name, date and time."
Else
For Each rCell In Selection
With rCell
.ClearComments
.AddComment
.Comment.Text Text:=sCmt
End With
Next
End If
Set rCell = Nothing
End Sub
VBA Code:
Sub swap()
Dim sCmt As String
Dim rCell As Range, range1 As Range, range2 As Range
sCmt = InputBox( _
Prompt:="Is the swap legal?" & vbCrLf & _
"Please add details of who actioned this swap and when.", _
Title:="Comment to Add")
If sCmt = "" Then
MsgBox "No details added. Please start again and include your name, date and time."
Else
For Each rCell In Selection
With rCell
.ClearComments
.AddComment
.Comment.Text Text:=sCmt
End With
Next
End If
Set rCell = Nothing
If Selection.Areas.Count <> 2 Then Exit Sub
Set range1 = Selection.Areas(1)
Set range2 = Selection.Areas(2)
If range1.Rows.Count <> range2.Rows.Count Or _
range1.Columns.Count <> range2.Columns.Count Then Exit Sub
range2.Offset(1) = range1.Value
range1.Offset(1) = range2.Value
range1.Font.Strikethrough = True
range2.Font.Strikethrough = True
End Sub
VBA Code:
Sub MarkShiftCovered_click()
Selection.Font.Color = RGB(0, 0, 0)
Selection.Interior.ColorIndex = xlNone
Selection.Font.Underline = False
Selection.Font.Bold = False
Selection.Font.Strikethrough = True
Dim sCmt As String
Dim rCell As Range
sCmt = InputBox( _
Prompt:="Have you covered this shift in it's entirety?" & vbCrLf & _
"Please add details of how the shift has been covered. ie. OFF roster, extensions.", _
Title:="Comment to Add")
If sCmt = "" Then
MsgBox "No details added. Please make sure the shift is fully covered."
Else
For Each rCell In Selection
With rCell
.ClearComments
.AddComment
.Comment.Text Text:=sCmt
End With
Next
End If
Set rCell = Nothing
End Sub
VBA Code:
Sub Copyandstrike()
Dim r As Integer, c As Integer
Dim sCmt As String
Dim rCell As Range
sCmt = InputBox( _
Prompt:="You are about to mark this shift as open." & vbCrLf & _
"Please add details on why this shift is now open. ie. absenteeism, training, meetings etc", _
Title:="Comment to Add")
If sCmt = "" Then
MsgBox "No details added. Please make sure the shift is fully covered."
Else
For Each rCell In Selection
With rCell
.ClearComments
.AddComment
.Comment.Text Text:=sCmt
End With
Next
End If
Set rCell = Nothing
If Selection.Cells.Count > 1 Then Exit Sub
c = Selection.Column '????*No check on validity of columnn!'
For r = 4 To 8
If Cells(r, c) = vbNullString Then
Cells(r, c).Value = Selection.Value
Cells(r, c).Interior.Color = RGB(255, 124, 128) 'Edit RGB values if necessary
Selection.Font.Strikethrough = True
r = 0
Exit For
End If
Next
If Not r = 0 Then MsgBox "There are no blanks left!"
End Sub