+ Reply to Thread
Results 1 to 7 of 7

Outputting individual cells to individual text files

  1. #1
    Registered User
    Join Date
    01-16-2013
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    9

    Outputting individual cells to individual text files

    Hi,

    Firstly, I'm not too good with VB programming (or even excel for that matter!), so perhaps my search terms weren't perfect, but I've looked high and low for a solution to this puzzle.

    I'm convinced it can be done as I've seen people doing *similar* things (ie importing FROM multiple files into different cells/workbooks) but nothing that matched my requirements - and unfortunately I don't have the know-how to pick apart their code and make it work in the way I need it to.

    Anyway, simply put, I have a bunch of data which makes up unique commands to run, so the files need to be individually named.

    In the most simplistic form, I have:

    A B
    1 command1
    2 command2
    3 command3
    4 command4

    I basically would like for instance a file to be created called 1.txt (or even .bat) which inside it contained Command1, then another called 2.txt with Command2 inside it

    And so on!

    Any pointers would be greatly appreciated

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Outputting individual cells to individual text files

    This should do it:

    Please Login or Register  to view this content.

    Be sure to edit the parts in red appropriately.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-16-2013
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Outputting individual cells to individual text files

    Hi Jerry

    Thanks for your reply.

    Please forgive my lack of knowledge here.

    So I've opened up Developer > Visual Basic

    I've gone to view code of the workbook, and have pasted in the code that you kindly sent to me.

    I changed the path to "C:\New\" and changed Sheet1 to Sheet 5.

    I ran it, and I'm getting an error 'Subscript out of range'.

    As the data I want to write to the file is in column 'L', I tried altering the code from Range("A:A") to ("L:L").

    The numbers of the files are in K, so I also tried ("K:L")

    Where am I going wrong (probably at the start!)

    Thanks again.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Outputting individual cells to individual text files

    Subscript out of range errors mean something you've named can't be found. Sheetname isn't 100% correct in some way, perhaps?

    Always hit DEBUG to see which line of code is having the problem.

    I misread the requirements. You want the files named for the number in column K, and column L has the text to write into that file?

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-16-2013
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Outputting individual cells to individual text files

    OK I've debugged it (thats a clever feature!), and it's stopping on the Set cmdRNG line (line 7)

    The sheet in question has been renamed, it is called 'Server List'

    In My VBAProject - the object tree shows:

    Sheet5 (Server List)

    I've therefore tried:
    Set cmdRNG = Sheets("Sheet5")
    Set cmdRNG = Sheets("Sheet5 (Server List)")
    Set cmdRNG = Sheets("Sheet5(Server List)")

    But with no luck. It is showing 'Run-time error '9': Subscript out of range'

    In regards to your question - yes that is what I'm trying to achieve. I can then modify as needed from there using batch files.

    Thanks

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Outputting individual cells to individual text files

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-16-2013
    Location
    England
    MS-Off Ver
    Excel 2013
    Posts
    9

    Re: Outputting individual cells to individual text files

    OK that seems to be better, I'm getting a different error

    If I just run the code, it says 'No cells were found'

    If I debug it, it stops on the same line - but it's showing Run-time error '1004'

+ 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