+ Reply to Thread
Results 1 to 2 of 2

To have DIR function accept a variable

  1. #1
    Registered User
    Join Date
    12-31-2020
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    13

    To have DIR function accept a variable

    So I have a code the lists down file names in folders and the following is the part of the code that responsible to fetch the name of the files

    Please Login or Register  to view this content.

    This code go through, as it's written, MyFileName = Dir(Key & "*17519*"), the code will fetch all files that has 17519 as part of the name. and it works just fine.

    I need to modify the code as per the following to make criteria of a specific text string in the file name be variable depending on the a value entered in a specific cell. so I did the following


    Please Login or Register  to view this content.
    But it didn't work, how can I have a variable be part of DIR function.

    below is the full code just for reference.


    Please Login or Register  to view this content.
    Last edited by alansidman; 01-21-2021 at 12:53 AM.

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,908

    Re: To have DIR function accept a variable

    If you need the W6 value to be part of the file name, you need to either put wildcards in that cell or use:

    Please Login or Register  to view this content.
    Rory

+ 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. IsError function doesn't accept value
    By CostCare in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-02-2017, 05:03 AM
  2. Adapt Formula to accept a variable
    By stuartgb100 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-19-2015, 01:49 PM
  3. countif won't accept variable for worksheet name
    By pandale in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-02-2014, 09:02 PM
  4. [SOLVED] Can a function be modified to accept a divisor?
    By Vba Novice in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-12-2013, 04:14 PM
  5. [SOLVED] Simple Problem--Can't Get VBA to Accept Variable in Cell Reference
    By One-Eyed Enos in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-09-2012, 09:36 AM
  6. RANDBETWEEN Does Not Accept a letter variable
    By tejista in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-03-2012, 05:56 PM
  7. Lock Cell Variable so it will only accept integers
    By gplush in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2007, 09:12 AM

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