Delete worksheet table based on date or blank date entry

Adrain

New Member
Joined
Jan 26, 2016
Messages
6
Hi

I would appreciate some help on the following problem, I have made a Excel table within a worksheet, wish to be able to allow the user to enter on a date, or leave a blank and delete the appropriate table row on the table when I ran the program it deleted row 10 of the worksheet, not the appropriate row on the table without affecting any other columns on worksheet.
Format that I am using is below followed by the program code that I was trying to achieve
1676694472078.png

Sub CellRowLoop()

Application.ScreenUpdating = False ' to make the program run faster
Dim lo As ListObject

idate = ActiveWorkbook.Worksheets("Sheet1").Range("d6") ' is the criteria on which the row is to be deleted

Set lo = Sheet1.ListObjects("tableentry")

For rw = lo.DataBodyRange.Rows.Count To 1 Step -1
If lo.DataBodyRange(rw, 3) = idate Then
lo.ListRows(rw).Delete
End If
Next

Application.ScreenUpdating = True

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
I am a bit confused.
This lo.DataBodyRange(rw, 3) is column 3 "of the table", aren't you trying to match the date in Column 1 of the table ?
 
Upvote 0
What follows DataRange has a context of DataRange ? Did changing the 3 to a 1 fix the issue ?
 
Last edited:
Upvote 0
Its actually more likely to be a data issue than a code issue but try this it should cover off some possible date issues.
VBA Code:
Sub CellRowLoop()

Application.ScreenUpdating = False ' to make the program run faster
Dim lo As ListObject
Dim idate As Long
Dim rw As Long

idate = CLng(ActiveWorkbook.Worksheets("Sheet1").Range("d6").Value2) ' is the criteria on which the row is to be deleted

Set lo = Sheet1.ListObjects("tableentry")

For rw = lo.DataBodyRange.Rows.Count To 1 Step -1
    If CLng(lo.DataBodyRange(rw, 1).Value2) = idate Then
        lo.ListRows(rw).Delete
    End If
Next

Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top