This code is inside of a module and it is activated when i select a cell then press my button "delete note". I was getting constant errors trying to write this so i turned to google and tried someone else's method which used filtering but it wouldn't work and i didn't like how it had to activate the sheet which contained the table anyway so i gave it another go writing my own code and have it almost working.
If i change this line:
If .DataBodyRange.Cells(Counter, .ListColumns("Name").Index) = EmployeeName And .DataBodyRange.Cells(Counter, .ListColumns("Date").Index) = SelectedDate Then
.ListRows(Counter).Delete
To this, then the macro works but obviously its deleted all names linked to that date instead of the name in cell "B3" on Sheet "Calendar"
If .DataBodyRange.Cells(Counter, .ListColumns("Date").Index) = SelectedDate Then
.ListRows(Counter).Delete
If i change it to this, i get a type mismatch error
If .DataBodyRange.Cells(Counter, .ListColumns("Name").Index) = EmployeeName
Full Code Below
Dim Counter As Integer, EmployeeName As Integer, LastRow As Integer, SelectedDate As Date
If Intersect(ActiveCell, range("D12:AS23")) Is Nothing Then
MsgBox "Please select a date.", , "Error"
Exit Sub
Else
If Sheets("Settings").range("Protected") = 2 Then
With Sheets("Calendar")
SelectedDate = Cells(ActiveCell.Row, 2) - 1 + ActiveCell.Value
EmployeeName = range("B3")
End With
With Sheets("Notes").ListObjects("TblNotes")
LastRow = .range.Rows.Count
For Counter = LastRow To 1 Step -1
If .DataBodyRange.Cells(Counter, .ListColumns("Name").Index) = EmployeeName And .DataBodyRange.Cells(Counter, .ListColumns("Date").Index) = SelectedDate Then
.ListRows(Counter).Delete
End If
Next Counter
End With
Else
'do nothing
End If
End If