Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Move file conditionally

0

This code will be placed in Step3.xlsb and only step3.xlsb is opened no other files are opened

So we have to open 1.xls by vba and check wheather the B2 cell of first sheet of 1.xls has data or not and do the same as per below condition

If B2 cell of 1.xls has data then

Set fso = CreateObject("scripting.filesystemobject")

    fso.MoveFile Source:="C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\Step1\Step1.xlsb", Destination:="C:\Users\WolfieeeStyle\Desktop\" ' replace with source and destination as required.

If B2 cell of 1.xls has no data blank cell then

Set fso = CreateObject("scripting.filesystemobject")

    fso.MoveFile Source:="C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\Step4\Step4.xlsb", Destination:="C:\Users\WolfieeeStyle\Desktop\" ' replace with source and destination as required.

Note- 1.xls first sheet name can be anything 

So plz have a look Sir

Answer
Discuss

Discussion

Please post your code and ask a question.
Variatus (rep: 4889) Sep 1, '19 at 5:07 am
Add to Discussion

Answers

0
Selected Answer
Sub STEP3()
    Dim ws As Worksheet, b2

    Set ws = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\1.xls").Worksheets(1)
    b2 = ws.[b2]
    ws.Parent.Close False

    With CreateObject("scripting.filesystemobject")
    If b2 <> "" Then
        .MoveFile Source:="C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\Step1\Step1.xlsb", _
            Destination:="C:\Users\WolfieeeStyle\Desktop\" ' replace with source and destination as required.
        Else
        .MoveFile Source:="C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\Step4\Step4.xlsb", _
            Destination:="C:\Users\WolfieeeStyle\Desktop\" ' replace with source and destination as required.
    End If
End With

End Sub


Discuss

Discussion

Thnx Mam For giving ur Precious time and Great Support to this Post
Have a Great Day Mam
and Thnx Variatus Mam
rider1234 (rep: 10) Sep 4, '19 at 9:04 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login