+ Reply to Thread
Results 1 to 8 of 8

Translate CELL("filename") to VBA

  1. #1
    Registered User
    Join Date
    09-06-2019
    Location
    Toronto, Canada
    MS-Off Ver
    2016
    Posts
    4

    Translate CELL("filename") to VBA

    I have managed parsing date (and convert to Excel date format) from the name of imported to Excel text file (path included). For the sake of this post is unnecessary complicate):

    =DATE(LEFT(MID(CELL("filename"),FIND("2",CELL("filename")),FIND("_",CELL("filename"))-FIND("2",CELL("filename"))-12),4),MID(MID(CELL("filename"),FIND("2",CELL("filename")),FIND("_",CELL("filename"))-FIND("2",CELL("filename"))-12),5,2),RIGHT(MID(CELL("filename"),FIND("2",CELL("filename")),FIND("_",CELL("filename"))-FIND("2",CELL("filename"))-12),2))

    How to move this function to VBA. I have tried formula: Range(""A1").Formula = "=...." and obviously it did not work. Argument of CELL in VBA can't have quotes. Result supposed to go to cell A1 of the ActiveWorksheet.

    I would appreciate help/suggestions
    Thank you
    Tomasz

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Translate CELL("filename") to VBA

    In VBA ANYTHING which in Excel has quotes needs to be enclosed in an additiona set of quotes in VBA
    e.g.

    Excel ="ABC" VBA = ""ABC""

    However please clarify what goal you are trying to achieve, not what you are currently doing to achieve your goal. It's not apparent to me at the moment
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Translate CELL("filename") to VBA

    Without seeing the filename that formula is parsing, it is kind of hard to know what it is doing. If you could post what CELL("filename") is returning to you, that would help. With that said, you can use this in VBA to get the filename itself (minus the path)...

    ThisWorkbook.Name

    If you need the path, use this...

    ThisWorkbook.Path

    Note that the path is returned without the trailing backslash, so it you need to put the two together, you will need to remember to add it.
    Last edited by Rick Rothstein; 09-10-2019 at 11:40 AM.

  4. #4
    Registered User
    Join Date
    09-06-2019
    Location
    Toronto, Canada
    MS-Off Ver
    2016
    Posts
    4

    Re: Translate CELL("filename") to VBA

    Thank you Richard for your willingness to help,
    my answer will be wordy, clear indication that I am a novice.
    1. Data is held in daily txt files in tab separated columns.
    2. only file name carries the date when file was collected.
    3. I want to "process" data from each of the *.txt files from some of the columns (to get min, max, graph etc.) and save the results in a spreadsheet, in dated rows. One row for each processed file, for each day.
    4. I have managed to have all steps in excel - practically manual process:
    - open txt file in excel
    - extract date by =CELL("filename") and reformat to excel DATE format
    - copy/paste to another spreadsheet - do "processing"
    - move results - one row per one file - to another spreadsheet (with a help of one macro allowing to place results in a new row).

    All works - with an inconvenience of few manual steps. Now I attempt to use macro(s) for the same.

    Tomasz

  5. #5
    Registered User
    Join Date
    09-06-2019
    Location
    Toronto, Canada
    MS-Off Ver
    2016
    Posts
    4

    Re: Translate CELL("filename") to VBA

    Thank you for the suggestion - I tried in VBA double quotation and it works, similar to Range.Formula("A1") = "=CELL(""filename"")"
    Cell A1 contains correctly parsed date from the file name. Now the question is how to automate the process (see my earlier response to Richard - below). Working on it.
    Thank you
    Tomasz

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Translate CELL("filename") to VBA

    Quote Originally Posted by tomaszs View Post
    2. only file name carries the date when file was collected.
    When I said "If you could post what CELL("filename") is returning to you, that would help." in Message #3, my hope was that you would post more than that above. What I would like you to do is put this formula in a cell in your file...

    =CELL("filename")

    and post back here what you see in the cell. Then we can use that to see what your formula is actually doing and then give you the VBA equivalent (which is what you asked for).

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Translate CELL("filename") to VBA

    As always a workbook is worth a thousand descriptions

  8. #8
    Registered User
    Join Date
    09-06-2019
    Location
    Toronto, Canada
    MS-Off Ver
    2016
    Posts
    4

    Re: Translate CELL("filename") to VBA

    I am sorry, my elaborate answer missed the point and did not satisfied any of you (Richard, Rick). My next posts will have more code and less words. At the moment double quote in VBA CELL(""filename"") solved immediate dilemma. txt file parsing works as well.

    Thank you

+ 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. Replies: 9
    Last Post: 03-09-2021, 11:54 PM
  2. [SOLVED] How to automatically add the Value of a spesific Cell into the "Save" filename?
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-11-2013, 12:55 PM
  3. Replies: 1
    Last Post: 09-09-2013, 11:41 AM
  4. CELL("filename") returns the same sheet name on three different sheets
    By 6StringJazzer in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-21-2013, 06:37 PM
  5. Circular Reference? - INDIRECT and CELL("filename") Usage
    By Nicked in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2012, 01:20 PM
  6. [SOLVED] "Save As" in current directory, filename from cell value
    By AlexCoyne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2012, 08:33 PM
  7. Replies: 0
    Last Post: 08-09-2012, 04:31 PM
  8. [SOLVED] CELL("filename") acting Volatile? (in assoc. with PULL)
    By [email protected] in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-03-2006, 10:40 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