SanjayGMusafir
Well-known Member
- Joined
- Sep 7, 2018
- Messages
- 1,513
- Office Version
- 2024
- Platform
- Windows
Dear Experts
Until yesterday the following code was working well for me. But for some reasons it has started behaving strange and deletes the column "Date" from the table. I'm unable to identify the problem so have stoped using the delete command for now. But need your help to find and rectify what's and why is going wrong way.
The purpose of this code is - To go to any blank row (no data) at the bottom of the table and delete the row if any such row exists, else it should go to a particular cell in "Date" column as per the date
Until yesterday the following code was working well for me. But for some reasons it has started behaving strange and deletes the column "Date" from the table. I'm unable to identify the problem so have stoped using the delete command for now. But need your help to find and rectify what's and why is going wrong way.
The purpose of this code is - To go to any blank row (no data) at the bottom of the table and delete the row if any such row exists, else it should go to a particular cell in "Date" column as per the date
Rich (BB code):
'Table is sorted with dates ascending before this command line
Range("SBISGM[[#Headers],[Date]]").Select
'To go to the bottom of the table
Selection.End(xlDown).Select
Range(ActiveCell.Offset(1, 0), ActiveCell.Offset(1, 0)).Select
'To test and select absolutely blank row if any
If Not Intersect(ActiveCell, ActiveSheet.ListObjects("SBISGM").DataBodyRange) Is Nothing Then
Intersect(ActiveCell.EntireRow, ActiveSheet.ListObjects("SBISGM").DataBodyRange).Select
Else
For Each cell In ActiveSheet.Range("SBISGM[Date]")
If cell.Value >= [Today()] And cell.Value < [Today()+15] Then
cell.Select
Exit For
End If
Next
End If
'To me problem seems in this command line, so stopped using it, after stopping this command line it works fine
'Range(Selection, Selection.End(xlDown)).Delete
'To find and delete any blank row that only contains table formulas but no other data
Dim r1 As Range, rows1 As Long, i1 As Long
Set r1 = ActiveSheet.Range("SBISGM")
rows1 = r1.rows.Count
For i1 = rows1 To 1 Step (-1)
If WorksheetFunction.CountA(r1.rows(i1)) = 0 Then r1.rows(i1).Delete
Next
For Each cell In ActiveSheet.Range("SBISGM[Date]")
If cell.Value >= [Today()] And cell.Value < [Today()+15] Then
cell.Select
Exit For
End If
Next