+ Reply to Thread
Results 1 to 10 of 10

Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

  1. #1
    Registered User
    Join Date
    04-17-2013
    Location
    Minnesota
    MS-Off Ver
    Excel 2003
    Posts
    11

    Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    I am working with a Parser that is kicking out columns of data into notepad and not excel. The columns are all sperated by "," and i need a quick way to send them to excel. I would like to find a way to create a macro that will open the sheet from a file location and do the following:
    Send column 1 of txt into sheet 1 column A:A
    Send column 3 of txt into sheet 1 column B:B
    Send column 5 of txt into sheet 1 column C:C
    Send column 7 of txt into sheet 1 column D:D

    I have attached a copy of the txt notepad file. The columns will all stay the same size but the rows will vary between 10 and several hundred. I also want to skip the final row as it a repeat of the previous row.

    If someone could give me some advice if i'm going to need to do arrays or what.

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    Hi,

    Something like this ?

    Please Login or Register  to view this content.
    GC Excel

    If this post helps, then click the star icon (*) in the bottom left-hand corner of my post to Add reputation.

  3. #3
    Registered User
    Join Date
    04-17-2013
    Location
    Minnesota
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    That is exactly it, thanks a done. I took the ' out to format the number as 1 2 3 4 5 6 and so on, the 0000000 were not neccessary. I do have one more question. I tried doing this but when cell C5 in sheet 2 is populated I would like to use that action to run the macro and use the cell value to find the specific file name in the folder. B12345 was an example I wanted to try this

    Open "C:\YourFolderHere\"Sheet(2):C5" & .txt" For Input As #1

    Will that work?

    I can write the macro to run when cell C5 is populated by

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "Sheet2$C$5" Then

    Call My Macro

    End If

    End Sub

    Please let me know if that will work or not

  4. #4
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    Like this ?

    Please Login or Register  to view this content.
    Last edited by GC Excel; 08-21-2013 at 03:51 PM. Reason: correct code

  5. #5
    Registered User
    Join Date
    04-17-2013
    Location
    Minnesota
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    I'm having trouble pulling this together. I have to create two modules?
    If I have module one for sheet one, do I have to create module two for sheet two? Do I have to have both modules for this to work?

  6. #6
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    Just use the last code I sent. You must insert it in "Sheet2 Module" only.
    When cell C5 will change on sheet2, the macro will launch and data should copy on sheet1.

  7. #7
    Registered User
    Join Date
    04-17-2013
    Location
    Minnesota
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    The program that I am parsing information no long places a "," prior to the first column in notepad. How do I get the code in excel pull the first column now when it looks for "," to define the LineText.

    I change the other arrays to do the following:

    Sheets(1).Cells(i, 2).Value = "" & arr(2)
    Sheets(1).Cells(i, 3).Value = "" & arr(4)
    Sheets(1).Cells(i, 4).Value = "" & arr(6)
    i = i + 1

    how do I get the code to reconize the first column with no "," I am assuming I am going to have to put that array in a seperate arr = Split

    Any info would be helpful.

  8. #8
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    Hi,
    First column is arr(0), so try this code :

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-17-2013
    Location
    Minnesota
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    I tried that already and it didn't work. It returned all zeros for column A:A and it returned the correct values for column B:B, C:C and D:D. Could I have done something wrong?

  10. #10
    Forum Expert
    Join Date
    08-02-2013
    Location
    Québec
    MS-Off Ver
    Excel 2003, 2007, 2013
    Posts
    1,414

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    Can you post an example of the new textfile you got now...

  11. #11
    Registered User
    Join Date
    04-17-2013
    Location
    Minnesota
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Create Macro to pull columns from a notepad document to colums of an excel spreadsheet

    Oh my last message didn't send. I have the new code working thanks for your help GC Excel

+ 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. Replies: 1
    Last Post: 08-29-2012, 08:25 AM
  2. Excel to find in Notepad and pull data lines
    By SunOffice in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-30-2011, 07:23 AM
  3. vba code question in excel to manipulate notepad document
    By lilsnoop in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-21-2009, 12:19 AM
  4. scan a document and pull into excel spreadsheet to edit
    By Tired of Typing so much in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-01-2006, 04:20 PM
  5. Create a macro to launch notepad while in Excel.
    By cheryljohnson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-22-2005, 08:06 AM

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