code not working

BBird

New Member
Joined
Oct 16, 2006
Messages
14
This code used to function correctly, however, it has stopped working and I cannot determine why. The computer that runs this file is now using Excel 2007 (it had been Excel 2003). However, this file is now no longer working in 2003 or 2007 and I am stumped.

Code:
Sub filemove()
'
' Created by Brian Birdsong 1/5/11
    Dim i As String
    Dim fso As Scripting.FileSystemObject
    Dim fname As String
    'i = "P"
    Set fso = New Scripting.FileSystemObject
    On Error GoTo Last
    
    For Each n In Range("C1:C100")
    
    Range("B1", ActiveCell.SpecialCells(xlLastCell)).Select
    'Selection.Find(What:=i, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
     '   :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
      '  False, SearchFormat:=False).Activate
    Selection.Find(What:="P", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
        
    'Selects the column "b" cell for file to move
    Range(ActiveCell, ActiveCell).Offset(0, -1).Select
    'Moves file to processed folder
    fname = fso.getfilename(ActiveCell.Offset(0, 1))
    fso.MoveFile "O:\AmericoldDataFiles\receivedFiles\Unprocessed\" & fname, "O:\AmericoldDataFiles\receivedfiles\Processed\"
    'Selects the B* and C* cells and delets them
    Range(ActiveCell, ActiveCell.Offset(0, 2)).Select
    Selection.ClearContents
    'End If

Next n
Last:
End Sub

column "b" data is a hyper link "\\server\share\americolddatafiles\receivedfiles\UnProcessed\testfiledonotuse.txt"

column "c" is either blank or "p"


The idea is for it to find the rows in column "c" that have a "p" in it and move the file referenced in column b to a "processed" folder. Thanks for any assistance.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I got it working again. The problem was in path for the move file part. I needed to change it to \\server\share\... instead of the O:\... that fixed it.
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top