+ Reply to Thread
Results 1 to 17 of 17

Copy specified data from notepad to excel

  1. #1
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Copy specified data from notepad to excel

    I have a several notepad text files saved in a location. I need a macro to get a section of information from each file to be copied to an excel sheet depending on the file names listed in column A of the sheet. The text file has data in the below mentioned format with each data separated by lines(---------------------),

    HTML Code: 
    if column B's header is DVB, the below data should be as copied

    DVB:

    xxxxx xxxxx
    xyz:xxxx
    xxx

    xxxx xxxxx xxxxx

    likewise if the header is ABC, then it should copy

    ABC:

    xxxxx xxxxx
    xyz:xxxx
    xxx

    xxxx xxxxx xxxxx

    xxxx xxxxx

    all the data from the header name(ABC) till the end of particular header's data that is till the line(-------) needs to be copied.

    Need help on this..Thanks in Advance!
    Last edited by sarajun_88; 04-09-2017 at 04:14 AM.

  2. #2
    Registered User
    Join Date
    11-19-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    2016
    Posts
    57

    Re: Copy specified data from notepad to excel

    Can you attach a copy of your workbook? Or at least clarify the following:
    Do you need to always loop through all txt files in folder or only those which names are in column A?
    Where on the worksheet should the extracted text go to, column C?

  3. #3
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83
    Quote Originally Posted by dOOb View Post
    Can you attach a copy of your workbook? Or at least clarify the following:
    Do you need to always loop through all txt files in folder or only those which names are in column A?
    Where on the worksheet should the extracted text go to, column C?
    Hello dOOb,

    Loop through Only those names in column A. The data should be extracted to column b,c...Etc., depending on the headers in the row 1.

  4. #4
    Registered User
    Join Date
    11-19-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    2016
    Posts
    57

    Re: Copy specified data from notepad to excel

    Let me know if this works:

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Re: Copy specified data from notepad to excel

    Quote Originally Posted by dOOb View Post
    Let me know if this works:

    Please Login or Register  to view this content.
    Thanks for your effort dOOb! But unfortunately this isn't working as expected.

    as requested earlier, please find the attached sample sheet.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Re: Copy specified data from notepad to excel

    I found this code on the web and this is working fine for one file at a time and displays the output in a msgbox.

    Is it possible to modify the code to loop through a set of files in a folder and fetch the data as an output to an excel sheet as in the sample sheet...

    HTML Code: 

  7. #7
    Registered User
    Join Date
    11-19-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    2016
    Posts
    57

    Re: Copy specified data from notepad to excel

    Hmm, I tested the code before posting it here and, to the extent I understood your requirement, it does exactly what you said it needs to do.
    I'm more than happy to help you troubleshoot this, but will need a bit more than "it isn't working as expected"
    In the file you attached, the filename in column A has no extension (.txt), is that the issue perhaps? Step through the code line by line with F8 and check where it fails.
    As for modifying the code you pasted, it certainly is possible.

  8. #8
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Re: Copy specified data from notepad to excel

    Quote Originally Posted by dOOb View Post
    Hmm, I tested the code before posting it here and, to the extent I understood your requirement, it does exactly what you said it needs to do.
    I'm more than happy to help you troubleshoot this, but will need a bit more than "it isn't working as expected"
    In the file you attached, the filename in column A has no extension (.txt), is that the issue perhaps? Step through the code line by line with F8 and check where it fails.
    As for modifying the code you pasted, it certainly is possible.
    Thank you for the prompt responses!!
    I tried without the extension .txt and the code is running fine and doesn't throw any errors but it isn't fetching any data. When i tried with the extension .txt the code throws error at the line, Set myTxtFile = FSO.OpenTextFile(FilePath, ForReading) 'this reads the file to "memory"

  9. #9
    Registered User
    Join Date
    11-19-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    2016
    Posts
    57

    Re: Copy specified data from notepad to excel

    What's the error description?
    You definitely need the file extensions for this to work, so either full names (i.e. "filename.txt") in your worksheet, or change this line of code:
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Try changing "ForReading" to "1" in the line that gives you the error.
    I doubt it's this, but just in case you haven't got the right reference selected, it may be.

    Also, this is working with Activesheet, so make sure the right one is active.

    This works for me as you can see:
    Capture.PNG

    Let me know how you get on.

  10. #10
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Re: Copy specified data from notepad to excel

    Quote Originally Posted by dOOb View Post
    What's the error description?
    You definitely need the file extensions for this to work, so either full names (i.e. "filename.txt") in your worksheet, or change this line of code:
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Try changing "ForReading" to "1" in the line that gives you the error.
    I doubt it's this, but just in case you haven't got the right reference selected, it may be.

    Also, this is working with Activesheet, so make sure the right one is active.

    This works for me as you can see:
    Attachment 511917

    Let me know how you get on.
    its working perfectly for you... but don't know why its not the same for me. i made all the changes suggested by you yet its not working for me. I get an error on the same statement --- run-time error '53': file not found but all the files are in place.

  11. #11
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83
    Quote Originally Posted by sarajun_88 View Post
    I found this code on the web and this is working fine for one file at a time and displays the output in a msgbox.

    Is it possible to modify the code to loop through a set of files in a folder and fetch the data as an output to an excel sheet as in the sample sheet...

    HTML Code: 
    dOOb,

    In this code I see that the output is given in the form of msgbx.. how to get them written to an excel file..

    Can u please help me on this? Really sorry about repeated requests..😑

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Copy specified data from notepad to excel

    Different method
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83
    Quote Originally Posted by jindon View Post
    Different method
    Please Login or Register  to view this content.
    Thanks a lot jindon! It's working perfectly.
    But my bad there are some portions where the data is like,
    EGN: xxx
    Hug: xxxxx

    In this case I need the header as EGN and paste the data Xxx in the row.

    As the code works only if there is ----- these sort of data's are not captured. Sorry for missing on this. Please help me on this...

  14. #14
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Copy specified data from notepad to excel

    Then I need to see few sample txt files.

  15. #15
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83

    Re: Copy specified data from notepad to excel

    Quote Originally Posted by jindon View Post
    Then I need to see few sample txt files.
    Please find the attached sample source and output files
    Attached Files Attached Files

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Copy specified data from notepad to excel

    Try this
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    11-22-2014
    Location
    US
    MS-Off Ver
    Office 365
    Posts
    83
    Quote Originally Posted by jindon View Post
    Try this
    Please Login or Register  to view this content.
    Thanks a lot jindon! It worked like a magic 😊

+ 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] Copy Excel data to Notepad file
    By rizmomin in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-19-2015, 11:01 AM
  2. Copy data from notepad into excel
    By platesigns in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-28-2014, 12:54 PM
  3. vbscript to copy data from excel to notepad
    By samiulla.warimani in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2014, 10:27 PM
  4. Macro to copy data from excel to notepad
    By emmamaki in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 05-19-2014, 03:42 AM
  5. [SOLVED] Copy excel data to notepad.
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2012, 08:56 AM
  6. [SOLVED] How do i copy columns of data in notepad into excel?
    By JJ in forum Excel General
    Replies: 1
    Last Post: 02-10-2005, 06:06 PM
  7. [SOLVED] How do i copy columns of data in notepad into microsoft excel?
    By JP in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-10-2005, 06:06 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