I have some code that allows a user to select multiple items from a list box and clear them out from the list. I'm trying to add a feature to allow the user to input comments for each entry if desired however the issue that I'm running into is that it will only ask for input once then it exits the loop regardless of how many items from the list box were selected. Prior to trying to add the inputbox to allow for comments the code would loop through the listbox and clear all entries that were selected just fine.
Code:
Any thoughts/ideas on how to accomplish this task would be greatly appreciated, thank you in advance for your time.
Code:
VBA Code:
Private Sub cmdupdate_Click()
'Updates, emails, and transfers requests to completed tab
Application.ScreenUpdating = False
Dim uniqueID As String
Dim r As Long
Dim lr As Long
Dim status As String
Dim c As Range
Dim strwho As String
Dim X As Long, FoundOne As Boolean
Dim strhrcomm As String
If optapproved.Value = False And optdenied.Value = False Then
MsgBox "Please select approved or denied for the selected request(s).", vbCritical, "Error.."
Exit Sub
End If
For X = 0 To ListBox1.ListCount
If ListBox1.Selected(X) Then
FoundOne = True
Exit For
End If
Next
If FoundOne = False Then
MsgBox "Please select request(s) to approve or deny.", vbCritical, "Error.."
Exit Sub
End If
If optapproved.Value = True Then
status = "Approved"
If MsgBox("Are you sure you would like to mark the highlighted item(s) on the previous form as approved?", vbYesNo, "Are you sure?") = vbYes Then
enterinitialsdenied:
strwho = InputBox("Please enter your initials below:", "Initials")
If StrPtr(strwho) = 0 Then
Exit Sub
ElseIf strwho = vbNullString Then
MsgBox "Please enter your initials:", vbCritical, "Error.."
GoTo enterinitialsdenied
Exit Sub
End If
For r = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(r) = True Then
'*****************************************************************************************************************************************
'TRYING TO INCORPORATE INPUTBOX TO ALLOW USER TO ADD COMMENTS IF DESIRED FOR EACH ENTRY **************************************************
'*****************************************************************************************************************************************
strhrcomm = InputBox("Please enter any comments/notes for " & ActiveCell.Offset(, 5).Value & "'s request:", "Comments/Notes")
uniqueID = ListBox1.List(r)
lr = Sheets("Approved").Range("A" & Rows.Count).End(xlUp).Row + 1
Windows("Electronic_TMAR.xlsm").Activate
Sheets("Requests").Select
Columns("A:A").Select
Cells.Find(What:=uniqueID, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(, 15).Value = "Approved"
ActiveCell.Offset(, 16).Value = UCase(strwho)
ActiveCell.Offset(, 17).Value = Format(Now(), "mm/dd/yyyy")
ActiveCell.Offset(, 18).Value = strhrcomm
Range(ActiveCell, ActiveCell.Offset(, 18)).Select
Selection.Copy
Workbooks("Electronic_TMAR.xlsm").Worksheets("Approved").Cells(lr, 1).PasteSpecial Paste:=xlPasteValues
Selection.Delete shift:=xlUp
Application.CutCopyMode = False
End If
Next
Call UserForm_Initialize
optapproved.Value = False
Else
Exit Sub
End If
ElseIf optdenied.Value = True Then
status = "Denied"
If MsgBox("Are you sure you would like to mark the highlighted item(s) on the previous form as denied?", vbYesNo, "Are you sure?") = vbYes Then
enterinitials:
strwho = InputBox("Please enter your initials below:")
If StrPtr(strwho) = 0 Then
Exit Sub
ElseIf strwho = vbNullString Then
MsgBox "Please enter your initials:", vbCritical, "Error.."
GoTo enterinitials
Exit Sub
End If
For r = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(r) = True Then
'*****************************************************************************************************************************************
'TRYING TO INCORPORATE INPUTBOX TO ALLOW USER TO ADD COMMENTS IF DESIRED FOR EACH ENTRY **************************************************
'*****************************************************************************************************************************************
strhrcomm = InputBox("Please enter any comments/notes for " & ActiveCell.Offset(, 5).Value & "'s request:", "Comments/Notes")
uniqueID = ListBox1.List(r)
lr = Sheets("Denied").Range("A" & Rows.Count).End(xlUp).Row + 1
Windows("Electronic_TMAR.xlsm").Activate
Sheets("Requests").Select
Columns("A:A").Select
Cells.Find(What:=uniqueID, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(, 15).Value = "Denied"
ActiveCell.Offset(, 16).Value = UCase(strwho)
ActiveCell.Offset(, 17).Value = Format(Now(), "mm/dd/yyyy")
ActiveCell.Offset(, 18).Value = strhrcomm
Range(ActiveCell, ActiveCell.Offset(, 18)).Select
Selection.Copy
Workbooks("Electronic_TMAR.xlsm").Worksheets("Denied").Cells(lr, 1).PasteSpecial Paste:=xlPasteValues
Selection.Delete shift:=xlUp
Application.CutCopyMode = False
End If
Next
Call UserForm_Initialize
optdenied.Value = False
Else
Exit Sub
End If
End If
End Sub
Any thoughts/ideas on how to accomplish this task would be greatly appreciated, thank you in advance for your time.