+ Reply to Thread
Results 1 to 2 of 2

New to VBA: what script to write so that a file is not saved if there's no payments?

Hybrid View

  1. #1
    Registered User
    Join Date
    03-22-2019
    Location
    London
    MS-Off Ver
    2016
    Posts
    1

    Question New to VBA: what script to write so that a file is not saved if there's no payments?

    Hi,

    I'm very new to VBA/ Macros so i'm not quite sure how to word it out but at the moment, in our workbook, if there's no payment a file is still automatically saved to our shared drive despite it being empty.

    This is the current script we have. What do I add or amend in order to fix this? I don't want it a file to save in our shared drive if it's empty.

    ' IMS Update
    
        Sheets("Force Doc").Select
        Rows("2:2").Select
        Selection.AutoFilter
        ActiveSheet.Range("$A$2:$Y$1002").AutoFilter Field:=3, Criteria1:="1"
        Sheets("Paste").Select
        Cells.Select
        Range("B2").Activate
        Selection.ClearContents
        Sheets("Force Doc").Select
        Range("D2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Selection.Copy
        Sheets("Paste").Select
        Range("B2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Rows("2:2").Select
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlUp
        IMSLoop = Workbooks(Date1 & ".xlsm").Sheets("Loop").Range("c2")
    
    
        Dim i As Integer
    
    For i = 1 To IMSLoop
    
        Application.DisplayAlerts = False
        Workbooks.Add
        Application.CutCopyMode = False
        ActiveWorkbook.SaveAs Filename:= _
            "\\fsp-sr1\Accounts\Department areas\Credit Control DCC\Delegate Uploader\Eventsforce\Output\" & Date1 & "\Temp.csv" _
            , FileFormat:=xlCSV, CreateBackup:=False
        Application.DisplayAlerts = True
    
        Windows(Date1 & ".xlsm").Activate
        Sheets("Paste").Select
        Rows("2:2").Select
        Range("B2").Activate
        Selection.Copy
        Windows("Temp.csv").Activate
        Rows("1:1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Columns("A:A").Select
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlToLeft
        Fname = "IMS" & i & " - " & Workbooks("temp.csv").Sheets("temp").Range("o1") & " - " & Workbooks("temp.csv").Sheets("temp").Range("A1")
    
        ActiveWorkbook.SaveAs Filename:= _
            "\\fsp-sr1\Accounts\Department areas\Credit Control DCC\Delegate Uploader\Eventsforce\Output\" & Date1 & "\" & Fname & ".csv" _
            , FileFormat:=xlCSV, CreateBackup:=False
        ActiveWindow.Close savechanges:=True
        Sheets("Paste").Select
        Rows("2:2").Select
        Range("B2").Activate
        Selection.Delete Shift:=xlUp
    
    Next i
    
        Sheets("Force Pay").Select
        Rows("2:2").Select
        Application.CutCopyMode = False
        Selection.AutoFilter
        ActiveSheet.Range("$A$2:$K$1002").AutoFilter Field:=3, Criteria1:="1"
        Range("D2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlToRight)).Select
        Selection.Copy
        Workbooks.Add
        ActiveSheet.Paste
        Rows("1:1").Select
        Application.CutCopyMode = False
        Selection.Delete Shift:=xlUp
        ActiveWorkbook.SaveAs Filename:= _
            "\\fsp-sr1\Accounts\Department areas\Credit Control DCC\Delegate Uploader\Eventsforce\Payments\IMS Payments - " & Date1 & ".csv" _
            , FileFormat:=xlCSV, CreateBackup:=False
        Windows("IMS Payments - " & Date1 & ".csv").Activate
        ActiveWorkbook.Close savechanges = True
        Windows(Date1 & ".xlsm").Activate
        
           
    
    End Sub
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 03-22-2019 at 09:43 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2411
    Posts
    26,715

    Re: New to VBA: what script to write so that a file is not saved if there's no payments?

    Welcome to the Forum ericinfo13!

    What do you mean by "empty"? It doesn't appear that you mean the file is literally completely empty. What is the condition that indicates that there is no payment?
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. script to run the macro from Vb script with out opening the excel file
    By chandanp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2021, 03:33 AM
  2. [SOLVED] Script to save to folder in "v:\dept2", confirm file saved, then delete from "v:\dept1"
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-28-2014, 11:42 AM
  3. How do I write a script for + or - results
    By rbaron in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-04-2012, 10:02 AM
  4. script to write 1's and zero's for cell color
    By NPeters in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-07-2010, 01:52 PM
  5. copy column-write a script
    By Kunal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-04-2005, 05:15 PM
  6. How to write script for a question
    By PeterG in forum Excel General
    Replies: 0
    Last Post: 02-22-2005, 10:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1