Results 1 to 17 of 17

Copy specified data from notepad to excel

Threaded View

sarajun_88 Copy specified data from... 04-09-2017, 04:10 AM
dOOb Re: Copy specified data from... 04-09-2017, 08:19 AM
sarajun_88 Hello dOOb, Loop through... 04-09-2017, 09:25 AM
dOOb Re: Copy specified data from... 04-09-2017, 11:51 AM
sarajun_88 Re: Copy specified data from... 04-10-2017, 07:22 AM
sarajun_88 Re: Copy specified data from... 04-10-2017, 08:12 AM
dOOb Re: Copy specified data from... 04-10-2017, 10:15 AM
sarajun_88 Re: Copy specified data from... 04-10-2017, 11:58 AM
sarajun_88 dOOb, In this code I see... 04-11-2017, 04:19 AM
dOOb Re: Copy specified data from... 04-10-2017, 01:40 PM
sarajun_88 Re: Copy specified data from... 04-10-2017, 02:24 PM
jindon Re: Copy specified data from... 04-11-2017, 04:59 AM
sarajun_88 Thanks a lot jindon! It's... 04-11-2017, 08:48 AM
jindon Re: Copy specified data from... 04-11-2017, 08:55 AM
sarajun_88 Re: Copy specified data from... 04-11-2017, 10:59 AM
jindon Re: Copy specified data from... 04-11-2017, 07:04 PM
sarajun_88 Thanks a lot jindon! It... 04-12-2017, 11:04 PM
  1. #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:

    Sub NewSub()
    
        Dim FSO As Object
        Dim Fld_obj As Object
        Dim File_obj As Object
        Dim FilePath As String
        Dim Hdr As String
        Dim myStr As String
        Dim myTxtFile
        Dim Txt_arr
        Dim i As Long
        Dim r As Long
        Dim c As Long
    
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set Fld_obj = FSO.GetFolder("C:\Text Files") 'update to your own folder
        
        With ActiveSheet
            For c = 2 To .UsedRange.Columns.Count 'define your end value differently if needed
                Hdr = .Cells(1, c).Value
                
                For r = 2 To .UsedRange.Rows.Count 'as above
                    Filename = .Cells(r, 1).Value
                    If FSO.FileExists(Fld_obj & "\" & Filename) Then
                        FilePath = Fld_obj & "\" & Filename
                        
                        Set myTxtFile = FSO.OpenTextFile(FilePath, ForReading) 'this reads the file to "memory"
                        Txt_arr = Split(myTxtFile.ReadAll, vbNewLine) 'this splits the text into array
                        
                        For i = 0 To UBound(Txt_arr) 'loop through text, find line matching the header
                            If Txt_arr(i) = Hdr Then
                                Do Until Txt_arr(i) Like "*------*" 'iterate until the "-----" line is found
                                    If myStr = vbNullString Then
                                        myStr = Txt_arr(i) & vbNewLine
                                    Else
                                        myStr = myStr & Txt_arr(i) & vbNewLine
                                    End If
                                    i = i + 1
                                Loop
                                .Cells(r, c).Value = myStr 'populate data in worksheet
                                myStr = vbNullString
                                Exit For
                            End If
                        Next i
                    End If
                Next r
            Next c
        End With
        
    End Sub
    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

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. 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