R
richg41
I am such a novice at this....I have the following code that partiall
works...(guess that means it doesn't work!)
I can cycle through the first do while loop and then the code crashe
with a run time error 91 -- Object variable or With Block variable no
set
Any support is much appreciated...I have very little pride o
authorship, I am just hoping to have code that does what I need.
What I simply need to do is look into a directory and read the files.
Then I want to cycle through the files looking into column "i" and fin
ALL instances of the word 'closed" Then I want to remove that row an
place it on a worksheet in the same workbook named closed. I want t
be able to repeat this for each file in the directory.
Here is what I have:
Private Sub CommandButton6_Click()
Application.ScreenUpdating = True 'to see whats happening
Dim i As Integer
With Application.FileSearch 'find files
.NewSearch
.LookIn = "C:\Test" 'Amend to suit
.SearchSubFolders = False
.Filename = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count 'increment count
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
'set first found file??
With wb.Worksheets("OPEN") 'name of worksheet is OPEN
' moves closed items in column i to sheet named closed
.Columns("I:I").Select ' CAUSES APPLICATION DEFINED ERROR
Do While Selection.Find(what:="closed", After:=ActiveCell
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
I can step through the code to this point then the error messag
appears.
ActiveCell.EntireRow.Select
Selection.Copy
ActiveSheet.Next.Select
Application.Goto Reference:="R3C1"
Selection.Insert shift:=xlDown
Application.CutCopyMode = False
ActiveWindow.SmallScroll Down:=0
ActiveSheet.Previous.Select
Selection.ClearContents
Selection.ClearContents
Selection.Delete shift:=xlUp
.Columns("I:I").Select
Loop
wb.Save
wb.Close
End With
Next i
End With
Application.ScreenUpdating = True
End Sub-I can step through the code to this point
works...(guess that means it doesn't work!)
I can cycle through the first do while loop and then the code crashe
with a run time error 91 -- Object variable or With Block variable no
set
Any support is much appreciated...I have very little pride o
authorship, I am just hoping to have code that does what I need.
What I simply need to do is look into a directory and read the files.
Then I want to cycle through the files looking into column "i" and fin
ALL instances of the word 'closed" Then I want to remove that row an
place it on a worksheet in the same workbook named closed. I want t
be able to repeat this for each file in the directory.
Here is what I have:
Private Sub CommandButton6_Click()
Application.ScreenUpdating = True 'to see whats happening
Dim i As Integer
With Application.FileSearch 'find files
.NewSearch
.LookIn = "C:\Test" 'Amend to suit
.SearchSubFolders = False
.Filename = "*.xls"
.Execute
For i = 1 To .FoundFiles.Count 'increment count
Set wb = Workbooks.Open(Filename:=.FoundFiles(i))
'set first found file??
With wb.Worksheets("OPEN") 'name of worksheet is OPEN
' moves closed items in column i to sheet named closed
.Columns("I:I").Select ' CAUSES APPLICATION DEFINED ERROR
Do While Selection.Find(what:="closed", After:=ActiveCell
LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
I can step through the code to this point then the error messag
appears.
ActiveCell.EntireRow.Select
Selection.Copy
ActiveSheet.Next.Select
Application.Goto Reference:="R3C1"
Selection.Insert shift:=xlDown
Application.CutCopyMode = False
ActiveWindow.SmallScroll Down:=0
ActiveSheet.Previous.Select
Selection.ClearContents
Selection.ClearContents
Selection.Delete shift:=xlUp
.Columns("I:I").Select
Loop
wb.Save
wb.Close
End With
Next i
End With
Application.ScreenUpdating = True
End Sub-I can step through the code to this point