Hi Everyone,
Hope everyone is doing well.
I found the following code to execute a macro in all excel files in a folder. Sounds amazing!
I have a code to add to it, (thanks again JB!), however I am having issues getting it to work.
If someone could please take a look at it and let me know what (more like, how many things) I have done wrong, it would be greatly appreciated.
I am adding this to the Sheet 1 Worksheet.
As usual, thanks in advance.
Sub Exec_Macro_For_All()
Dim sPath As String
Dim sFile As String
Dim sDir As String
Dim oWB As Workbook
Dim i1 As Long
Dim iMax As Long
On Error GoTo Err_Clk
sPath = C: Documents MyDocuments \ looptest
If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
sDir = Dir$(sPath & "*.xls", vbNormal)
Do Until LenB(sDir) = 0
Set oWB = Workbooks.Open(sPath & sDir)
JB's code
Option Explicit
Sub DeleteDoc68()
'Locate "PEFP" and delete all rows with ID from that match
Dim rFound As Range, rID As String, i As Integer, lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = True
On Error Resume Next
Do
With Sheet1
Set rFound = .Columns(1).Find(what:="PEFP", After:=.Cells(1, 1), _
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows)
On Error GoTo 0
If Not rFound Is Nothing Then
rID = Cells(rFound.Row, 2).Value
For i = lastrow To 2 Step -1
If Cells(i, 2).Value = rID Then Rows(i).EntireRow.Delete Shift:=xlUp
Next i
End If
End With
Loop Until rFound Is Nothing
Application.ScreenUpdating = True
End Sub
oWB.Save
oWB.Close False
sDir = Dir$
Loop
Err_Clk:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
In all honesty, this is a bit overwhelming for me.
Bookmarks