I have two sheets: INVOICES sheet has a list in column B of ID numbers say 1000-3000 and LineItems sheet which is empty.
Currently, users enter in pending invoice information into the userform (including an ID number) and then click send and the information is entered into the INVOICES sheet based on the ID number (which is preexisting on the INVOICES sheet) and also onto the LineItems sheet into the next empty row. This works just fine. Where I am having trouble is once the invoice is approved, the send button enters in the approval date and "Approved" in the correct column of the corresponding row of the INVOICES sheet (again using the match function based on the ID number) but I cant figure out how to enter the approval date and "Approved" in the corresponding row of the LineItem sheet since the ID number is not preexisting. I have tried to loop through the LineItems sheet looking for the entered ID number, but it's not working. Maybe someone can help? Below is a bit of the code I am referring to. Many thanks to anyone who can help me with this issue I have been struggling with for days!
Private Sub SaveButton_Click()
If ApprovedButton = True Then
'are you sure you want to send message
Sendmsg = MsgBox(Prompt:="Are you sure you're ready to send?", _
Buttons:=vbYesNo, Title:="Warning")
If Sendmsg = vbYes Then
'enter approval date into corresponding row
If IsNumeric(IDNumberBox) Then
Nextrow = Application.WorksheetFunction.Match(CLng(IDNumberBox), Range("B:B"), 0)
Else
Nextrow = Application.WorksheetFunction.Match(IDNumberBox, Range("B:B"), 0)
End If
Cells(Nextrow, 18) = ApprovalDateBox.Text
Cells(Nextrow, 19) = "Approved"
'****here is the loop I tried, but does not work***
Dim i As Integer
i = 1
Do While Worksheets("LineItems").Cells(i, 1) <> ""
If Worksheets("LineItems").Cells(i, 1).value = IDNumberBox.value Then
Worksheets("LineItems").Cells(i, 9) = ApprovalDateBox.Text
Worksheets("LineItems").Cells(i, 10) = "Approved"
End If
i = i + 1
Loop
End If 'msg box
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End If 'approved
End Sub
Bookmarks