Hello,
I have been working on something for a while now and I've hit a brick wall. I have a command button that I need to add functionality to. It needs to search a different sheet for a name/date combination. I know how to search for 1 at a time, but not both. Or make it search from the bottom going up. That would work for me as well. Then I could just find the last entry of the name and check the date on it. If you look at the sheet, you will see what I am working with. Basically, the button checks the cells to make sure data is entered, then it adds the pertinent data to the other sheet. I would like to have it check to see if the data is already there. Since the names will come up more than once, I cannot just search for that and since there will be multiple people per day, I cant search by date either, it has to be both.
Here is the code for the button:
Sub Main2()
Dim MyRow As Integer
MyRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row
Dim LastRow As Integer
LastRow = Sheets("Log").Range("A" & Rows.Count).End(xlUp).Row
If Sheets("A-M").Cells(MyRow, 3).Value = 0 Or Sheets("A-M").Cells(MyRow, 4).Value = 0 Then
MsgBox "Please fill in all of the fields.", vbCritical, "Cancelled"
Else
Sheets("Log").Activate
Sheets("Log").Cells(LastRow + 1, 1).Value = Sheets("A-M").Cells(MyRow, 1).Value
Sheets("Log").Cells(LastRow + 1, 3).Value = Sheets("A-M").Cells(MyRow, 3).Value
Sheets("Log").Cells(LastRow + 1, 4).Value = Sheets("A-M").Cells(MyRow, 4).Value
Sheets("Log").Cells(LastRow + 1, 2).Value = Format(Now, "MM/DD/YY")
Cells(LastRow + 1, 1).Select
Sheets("A-M").Cells(MyRow, 3).ClearContents
Sheets("A-M").Cells(MyRow, 4).ClearContents
End If
End Sub
Oh! and it's a location based dynamic button. It takes a value from the row it is on for most of the calculations and data transfer. The button can exist on any row on the sheet... makes it idiot proof... Kinda.
Any help would be appreciated.
Bookmarks