+ Reply to Thread
Results 1 to 21 of 21

VBA To Log To External File - Cell Value Dependent

  1. #1
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    VBA To Log To External File - Cell Value Dependent

    I have a file that pings some data to an external file. Everything works great. I'd like to expand on it, if possible, though. This file will be given to 6 different groups of people. Each person will have to select their group from a drop down box. Depending on which group they are in, I need a different external file to be chosen. I don't know if a variable can be added to the current code to add in those different group choices or not. I'm curious if someone might can take a look at it and see if it can be altered to accommodate what I'm trying to achieve?

    The attached example file will explain everything clearly.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: VBA To Log To External File - Cell Value Dependent


    So obviously it can't be a constant anymore but a String variable …

    LogFileName = "P:\Engineering\Engineering Tool Logs\" & [B7] & ".txt"

  3. #3
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332
    So that’s all I would change?

  4. #4
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Marc L View Post

    So obviously it can't be a constant anymore but a String variable …

    LogFileName = "P:\Engineering\Engineering Tool Logs\" & [B7] & ".txt"
    Ok... after I read this, it makes sense what you are saying now but I'm having an issue getting it to work. My actual file contains more sheets and the variable is located on a sheet in the background so I need the LogFileName to point to B7 in that sheet, not the active sheet. I've tried different variations of your suggestion but can't seem to get it to work.

    Please Login or Register  to view this content.
    Can you tell me where I'm messing up in the path there?

  5. #5
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: VBA To Log To External File - Cell Value Dependent

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    To add: I'm getting the Compile Error: Constant Expression Required and it's highlighting .Range

  7. #7
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: VBA To Log To External File - Cell Value Dependent

    Remove [ and ]

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Gtrtim112 View Post
    Please Login or Register  to view this content.
    Can you tell me where I'm messing up in the path there?
    LogFileName = "P:\Engineering\Engineering Tool Logs\" & Sheets("Variables").[B7] & ".txt"

  9. #9
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Marc L View Post
    LogFileName = "P:\Engineering\Engineering Tool Logs\" & Sheets("Variables").[B7] & ".txt" …

    I'm still getting the same error. Now, though, it's highlighting ".B7"


    Please Login or Register  to view this content.

  10. #10
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Gtrtim112 View Post
    Quote Originally Posted by Marc L View Post
    LogFileName = "P:\Engineering\Engineering Tool Logs\" & Sheets("Variables").[B7] & ".txt" …

    I'm still getting the same error. Now, though, it's highlighting ".B7"


    Please Login or Register  to view this content.
    It is also highlighting the very first line:
    Please Login or Register  to view this content.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,931

    Re: VBA To Log To External File - Cell Value Dependent

    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  12. #12
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by AliGW View Post
    Administrative Note:

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. No help to be offered until the link is provided.)
    Ali, I didn't realize that was a rule, sorry. As info... I ALWAYS post that a solution has been made and do not waste anyone's time. I think my track record shows this. Ask the countless people I've given reputation to.

    Anyways... here's your request.

    https://www.mrexcel.com/board/threads/log-to-external-file-vba.1130492/#post-5465044

    May the replies/help resume or am I on probation by the forum police?

    Am I supposed to explain what I edited per the rules? I corrected the spelling of one word.
    Last edited by Gtrtim112; 04-12-2020 at 05:41 PM.

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: VBA To Log To External File - Cell Value Dependent


    As I yet wrote in post #2 so again « it can't be a constant anymore but a String variable » ! So just compare my post #8 and your post #9 …

  14. #14
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Marc L View Post

    As I yet wrote in post #2 so again « it can't be a constant anymore but a String variable » ! So just compare my post #8 and your post #9 …
    Marc, I get what you are saying but I don’t know how to change it.

  15. #15
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Gtrtim112 View Post
    Marc, I get what you are saying but I don’t know how to change it.
    Do I just take out the “Const”?

  16. #16
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA To Log To External File - Cell Value Dependent


    As the codeline was yet written twice in posts #2 & 8 without 'Const' …

  17. #17
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Found the answer I was looking for...

    Thanks to all that tried to help me and sorry if I didn't understand the answers given to me. I'm not good with code. I know how to put it in if it's spelled out for me but I can't interpret most of it.

    This is the code that worked for me (with slight modification on the path):

    Please Login or Register  to view this content.

  18. #18
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Marc L View Post

    As the codeline was yet written twice in posts #2 & 8 without 'Const' …
    As info... Excel would not accept it without "Const" in it. The whole line highlighted in red when I did that.

  19. #19
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Gtrtim112 View Post
    As info... Excel would not accept it without "Const" in it. The whole line highlighted in red when I did that.
    Photo of error attached
    Attached Images Attached Images

  20. #20
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: VBA To Log To External File - Cell Value Dependent


    Your bad again ! As your codeline is very not mine, compare them ‼ That's just about to well read, nothing else …

    As a reminder, in VBA the declaration of any variable must be in a Dim codeline like you can see in your code or in VBA help.

  21. #21
    Forum Contributor Gtrtim112's Avatar
    Join Date
    04-12-2013
    Location
    Alabama, USA
    MS-Off Ver
    Excel 2016
    Posts
    332

    Re: VBA To Log To External File - Cell Value Dependent

    Quote Originally Posted by Marc L View Post

    Your bad again ! As your codeline is very not mine, compare them ‼ That's just about to well read, nothing else …

    As a reminder, in VBA the declaration of any variable must be in a Dim codeline like you can see in your code or in VBA help.
    Marc,

    I'm not sure what I've done to make you angry at my questions but rest assured that you should not feel the need to answer me ever again. I came here for help and I've been using this forum for about 6 years without the first issue. Not everyone knows code like you, nor can we interpret what you post as easily as you think. You take for granted that you know VBA while others are still learning. You definitely do not have a future in training as you would not have the patience with people such as myself. So, thank you for making feel like I should not have came here for assistance in the first place but I will continue using this forum as a source for help as everyone else that has helped me in the past, have done so without the condescending attitude that you've presented towards me.
    I would just like to note also, that I made sure to leave you positive reputation for your meager attempt to help me because it's the right thing to do and you definitely seem to need some positivity in your life.

    Good day

+ 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. [SOLVED] External Links result in #VALUE errors when external file is closed
    By ziggyztz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-24-2019, 04:41 PM
  2. Replies: 0
    Last Post: 01-29-2019, 07:11 PM
  3. [SOLVED] Use value in cell as source to external file
    By c00ly81 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2016, 01:57 PM
  4. External Data from Microsoft Query - Excel File - Causes external file to open.
    By lee1000d in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-25-2015, 02:25 PM
  5. Replies: 1
    Last Post: 03-19-2013, 05:45 AM
  6. save to file dependent on cell
    By sdts in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-26-2010, 04:55 AM
  7. External File(s) referenced and file links change based on row cell.
    By Jimmydageek in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-23-2009, 02:59 PM

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