+ Reply to Thread
Results 1 to 8 of 8

Macro for Import Text file and convert it in Excel

  1. #1
    Forum Contributor
    Join Date
    02-17-2014
    Location
    INDIA
    MS-Off Ver
    Excel 2010
    Posts
    320

    Macro for Import Text file and convert it in Excel

    Today i am facing a problem...........i want to make many macro and try it on my Text file but nothing is going to right........

    Below code i got from Recording Macro.........Below code including Text File opening + Set Break Line + Sort on COL-A and more more more................

    i am looking for a solution, i want to make it dynamically......means that when i click on Commandbutton1, a open dialog box should be open like CTRL+O, where i choose my TextFile from my Desktop and it convert in Excel.........
    Please see the excel file's Sheet Deletion

    I am attaching 2files i.e. 1. TextFile and 2. Excel File, please see


    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Contributor
    Join Date
    02-17-2014
    Location
    INDIA
    MS-Off Ver
    Excel 2010
    Posts
    320

    Re: Macro for Import Text file and convert it in Excel

    After some amendments the below code is working for me but some bugs in it.......i want anyone can help to correct below mentioned code, please see:-

    1. We are in Sheet1, When i click on Commandbutton1_Click(), a open dialog box will be open, if i click on Cancel Button it automatically import and convert the text file which you will see in the "TEXT;C:\Users\Gyan Verma\Desktop\July-2018 Advance\slgb0718.prn"

    I want it should be worked on my choice of Text File and convert it in excel, so i want to correct this command line

    by default it is always convert slgb0718.prn file

    2. We are also in Sheet1, Click on Commandbutton1_Click(), now it create a sheet namely "Deletion" in existing workbook and data of Textfile should be in this "Deletion" Sheet.


    Please Login or Register  to view this content.
    Please correct it

  3. #3
    Forum Contributor
    Join Date
    02-17-2014
    Location
    INDIA
    MS-Off Ver
    Excel 2010
    Posts
    320

    Re: Macro for Import Text file and convert it in Excel

    please see the below code it gives me error on .Refresh BackgroundQuery:=False


    Please Login or Register  to view this content.

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro for Import Text file and convert it in Excel

    I found this code at "StackOverflow" made by a person named "Omar" so all credit goes to him. It seems that you can use multi selection in his macro.

    I've added some bits and pieces at the end to organize the data to get the same result in your uploaded file. The problem I had was if the persons name was 15 characters long. That made part of the name spill over from the D column to the E column so the macro checks for this and writes a warning on the same row but in the G column.

    Please Login or Register  to view this content.

    Alf
    Last edited by Alf; 09-14-2018 at 02:11 PM.

  5. #5
    Forum Contributor
    Join Date
    02-17-2014
    Location
    INDIA
    MS-Off Ver
    Excel 2010
    Posts
    320

    Re: Macro for Import Text file and convert it in Excel

    Thankyou sir it is working flawless
    Last edited by AVG123; 09-15-2018 at 03:00 AM.

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro for Import Text file and convert it in Excel

    You are welcome and thanks for feedback. As this seems to have solved your problem could you please mark thread "Solved" as per forum rules.

    Alf

    To mark your thread solved do the following:
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

  7. #7
    Forum Contributor
    Join Date
    02-17-2014
    Location
    INDIA
    MS-Off Ver
    Excel 2010
    Posts
    320

    Re: Macro for Import Text file and convert it in Excel

    Thanks for help...........
    Sir it is working fine but some issue are not solved in this code:-
    my folder have "slgb0818.prn", "slgb1217.prn"
    and it is always working on "slgb0818.prn" file because it have slgb0...prn in file name (Please see bold part is 0), if i will change my second file name from "slgb1217.prn" to "slgb0217.prn" then code is working. if file name contain 5th character 0 then it is working otherwise not working..........
    and same case in .TXT file

    2. i want to work on multiple extensions i.e. ".TXT",".PRN" how to add second extension in the code

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro for Import Text file and convert it in Excel

    Ok I've changed the code a bit and now you see both ".txt" and ".prn" files and macro runs without problems. But as you have not uploaded your "slgb0718.png" file I've renamed the "slgt718.txt" you uploaded to a number of different name vise that is png files.

    Please Login or Register  to view this content.
    Alf

+ 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. Need a Macro code to convert Text file into Excel format
    By Vel Iyappan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2017, 08:00 AM
  2. VBA code to Convert Excel to Text file of DML statements(Insert) using Macro
    By kavitha.v in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2014, 08:52 AM
  3. How can I write a macro to import multiple text file iinto the same excel worksheet
    By pvimalmec in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-07-2013, 04:11 PM
  4. Import several text files into an excel file with macro
    By rhkm in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2013, 05:04 AM
  5. Replies: 8
    Last Post: 11-12-2012, 02:39 PM
  6. Import Tab Seperated Text File Into Excel Using Macro
    By SameeraCharabudla in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2012, 11:57 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