I wonder if somebody could help me with the VBA code below. Currently the code will delete all the files that have been selected in the spreadsheet. I notice that if I filter the rows and make a selection it will delete all the hidden rows also. How can I amend the code to delete just the visible cells in the selection.
Thanks in advance
Code:
Sub DelFiles()
Dim blnDelAll As Boolean
Dim rngVal As Range
Dim rngCl As Range
Set rngVal = Selection 'Columns("I").SpecialCells(xlCellTypeVisible)
'Set rngVal = Columns("I").SpecialCells(xlCellTypeVisible)
On Error Resume Next
For Each rngCl In rngVal.Cells
Recycle rngCl.Value
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
If Err.Number <> 0 Then
Err.Clear
rngCl.Offset(, 1) = "File not found"
blnDelAll = True
End If
Next
On Error GoTo 0
If blnDelAll Then
MsgBox "Some File were not deleted, invalid path or you do not have permission to delete this file."
Else
MsgBox "All Files successfully deleted."
End If
End Sub
Thanks in advance