+ Reply to Thread
Results 1 to 2 of 2

Make Cells Visible Only If Another File Exists

Hybrid View

  1. #1
    Registered User
    Join Date
    06-19-2013
    Location
    Fayetteville, Arkansas, USA
    MS-Off Ver
    2007
    Posts
    10

    Question Make Cells Visible Only If Another File Exists

    I have a sheet that summarizes data for several scenarios and displays them. Currently, the cells for all scenarios constantly display some data, the data that were the last to be saved as each respective scenario. However, I only want the data to display in the cells if there is actually a corresponding scenario saved in the same path as the current workbook.

    My thoughts tell me this would need to be a macro that runs upon the opening of the current workbook. Then it would need to re-execute anytime a new scenario is saved while the current workbook is open (The SaveScenario macro runs from the current workbook, creates the scenario workbook, and copies the scenario summary data into the cells in question).

    Please Help.

    Thank you very much.
    Grant West
    Program Associate
    Agri Econ
    U of AR

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Make Cells Visible Only If Another File Exists

    As a starting point, you could probably use a function like this:
    Function file_exists(file_name As String)
    Dim fs, fil, fol
    Set fs = CreateObject("Scripting.filesystemobject")
    Set fol = fs.getfolder(ThisWorkbook.Path)
    Do
        For Each fil In fol.Files
            If fil.Name = file_name Then Exit Do
        Next
        file_exists = True
    Loop
    If Not file_exists = True Then file_exists = False
    End Function
    to check if the workbook exists.

    Then something along the lines of:
    if file_exists("Workbook Name") = false then 
       'hide data
    else
       'show data
    end if

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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