I've never posted on here before so let me know if you need more information. I'm also not an expert in coding but have been doing basic coding for awhile.
I created an inventory tracking sheet but some of the products were being entered more than once. I'm trying to create a find system that uses the formula ID number and the date last created that will change the font color if the product already exists in the table.
The macro runs great if I click run in the visual basic editor but will only return false results when I run it from the command button on the excel sheet. No errors pop-up.
I am using excel 2007
When I run the code from the userform on the excel sheet, I choose a date and formulaID that at on the table and should return true (and does if run from the editor). So, i feel like the problem is in the "ws.Cells(i, "H") = frmNewInv.dtpFindDate" and possibly something with formatting?!?
The date is inputted into the table using the date-time picker and I am also using the dtpicker to choose a date to find with formaulaID in the table.
Thank you
I created an inventory tracking sheet but some of the products were being entered more than once. I'm trying to create a find system that uses the formula ID number and the date last created that will change the font color if the product already exists in the table.
The macro runs great if I click run in the visual basic editor but will only return false results when I run it from the command button on the excel sheet. No errors pop-up.
I am using excel 2007
Code:
Sub FindItem()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Generated Samples")
Dim i As Long, Endrow As Long, answer As Integer, answer1 As Integer, answer2 As Integer
'Msg Box
If frmNewInv.ListFormulaID = "" Then
answer = MsgBox("Please select a Formula ID number.", vbCritical, "Please Complete")
Exit Sub
End If
Endrow = ws.Cells(Rows.Count, 1).End(xlUp).Row
For i = 7 To Endrow
If ws.Cells(i, 1) = frmNewInv.ListFormulaID And ws.Cells(i, "H") = frmNewInv.dtpFindDate Then
ws.Cells(i, 1).EntireRow.Font.ColorIndex = 3
frmNewInv.Hide
answer1 = MsgBox("Item Found.", vbOKCancel + vbInformation, "Found Item")
If answer1 = vbOK Then
ws.Cells(i, 1).EntireRow.Font.ColorIndex = 1
frmNewInv.Show
Else
ws.Cells(i, 1).EntireRow.Font.ColorIndex = 1
Unload frmNewInv
End If
ElseIf ws.Cells(i, 1) = frmNewInv.ListFormulaID And ws.Cells(i, "H") <> frmNewInv.dtpFindDate Then
answer2 = MsgBox("Item does not exist.", vbExclamation, "No Item Found")
End If
Next i
End Sub
When I run the code from the userform on the excel sheet, I choose a date and formulaID that at on the table and should return true (and does if run from the editor). So, i feel like the problem is in the "ws.Cells(i, "H") = frmNewInv.dtpFindDate" and possibly something with formatting?!?
The date is inputted into the table using the date-time picker and I am also using the dtpicker to choose a date to find with formaulaID in the table.
Thank you