Mar 24 2022 08:33 PM
first of all huge thank you to all the member who helped me in accomplish my project, I m 99%done.
what i need to complete is a way to delete the row from the below table if the the relative file is not found any more in the folder. The text In the column PRODUCT NAME is the same of the file name.
Mar 24 2022 08:42 PM
Mar 25 2022 09:38 PM
@Subodh_Tiwari_sktneer thank you for taking the time to help,
here is the file.
Mar 25 2022 10:27 PM
Solution
You may try the following code to delete a table row if a recipe card doesn't exist. You may click the button in cell M1 in the attached to run the macro.
Sub DeleteTableRowIfFileDoesNotExist()
Dim ws As Worksheet
Dim tbl As ListObject
Dim fso As Object
Dim i As Long
Dim strFilePath As String
Application.ScreenUpdating = False
Set ws = ThisWorkbook.Worksheets("Sheet1")
Set tbl = ws.ListObjects("Table1")
Set fso = CreateObject("Scripting.FileSystemObject")
For i = tbl.DataBodyRange.Rows.Count To 1 Step -1
strFilePath = tbl.ListColumns("CLICK TO OPEN RECIPE CARD").DataBodyRange.Cells(i).Value
If Not fso.fileexists(strFilePath) Then
tbl.ListRows(i).Delete
End If
Next i
Application.ScreenUpdating = True
End Sub
Mar 25 2022 10:44 PM
Mar 25 2022 11:52 PM
Mar 25 2022 10:27 PM
Solution
You may try the following code to delete a table row if a recipe card doesn't exist. You may click the button in cell M1 in the attached to run the macro.
Sub DeleteTableRowIfFileDoesNotExist()
Dim ws As Worksheet
Dim tbl As ListObject
Dim fso As Object
Dim i As Long
Dim strFilePath As String
Application.ScreenUpdating = False
Set ws = ThisWorkbook.Worksheets("Sheet1")
Set tbl = ws.ListObjects("Table1")
Set fso = CreateObject("Scripting.FileSystemObject")
For i = tbl.DataBodyRange.Rows.Count To 1 Step -1
strFilePath = tbl.ListColumns("CLICK TO OPEN RECIPE CARD").DataBodyRange.Cells(i).Value
If Not fso.fileexists(strFilePath) Then
tbl.ListRows(i).Delete
End If
Next i
Application.ScreenUpdating = True
End Sub