+ Reply to Thread
Results 1 to 7 of 7

VBA excel read random line from text file

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    Krakow
    MS-Off Ver
    Excel 2007
    Posts
    10

    VBA excel read random line from text file

    Hi,

    I have flat text file
    I need to read random line from txt file and put into cell

    I have code :

    Please Login or Register  to view this content.
    ---------- or code :

    Please Login or Register  to view this content.
    Last edited by Cutter; 08-01-2012 at 06:02 PM. Reason: Added code tags

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA excel read random line from text file

    VBAxxx,

    Welcome to the forum!
    In the future, please use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here.

    As to your question, it looks you have a tab delimited text file. Do you want one random part of one random line put into a single cell? Or do you want all of one random line split into a row of cells? Are there any restrictions on where the random line (and/or random part from the line) can come from in the text file?
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Registered User
    Join Date
    08-01-2012
    Location
    Krakow
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA excel read random line from text file

    in the file is about 2000 lines , one value in one row , for example :
    ------------
    Test1
    Test2
    Test3
    Test4
    ----------

    And I need read random line(value) from this file and paste into Excel Cell

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA excel read random line from text file

    VBAxxx,

    Give this a try:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    08-01-2012
    Location
    Krakow
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA excel read random line from text file

    it works! , Thx ! ! ! ! !

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: VBA excel read random line from text file

    You're very welcome

    If that takes care of your need, please mark this thread as solved.
    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  7. #7
    Registered User
    Join Date
    02-14-2017
    Location
    chennai
    MS-Off Ver
    MS-OFFICE_7
    Posts
    1

    VBA excel read random line from text file

    Hi,
    tigeravatar

    I am trying to extract the Information from Notepad to Excel through VBA..

    My Quiery is I have some Text files.. Lets

    Text1
    Text2
    Text3
    Text4

    Text1 file I need some information to be extracted (i.e.., after 20 lines my information will be there) should be extracted from 20th line till end

    so could you please help me out in this Waiting for your reply and code..

    Thanks
    Mani deepa

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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