+ Reply to Thread
Results 1 to 5 of 5

Open text file and copy specific rows into spreadsheet column

Hybrid View

  1. #1
    Registered User
    Join Date
    07-16-2014
    Location
    Sweden
    MS-Off Ver
    2010
    Posts
    7

    Open text file and copy specific rows into spreadsheet column

    Hello,

    I'm looking for a macro that can copy specific rows from an text file into a spreadsheet.
    My text file is looking like this:
    INPUT: f[MHz] input[dBm]
    80.000000 52.217000
    80.800000 52.004992
    81.608000 51.601915
    ...

    Where I want to copy the "52.217000", "52.004992", "51.601915" and followed by 254 rows of different numbers "51....".

    How do I do that?

  2. #2
    Registered User
    Join Date
    07-16-2014
    Location
    Sweden
    MS-Off Ver
    2010
    Posts
    7

    Re: Open text file and copy specific rows into spreadsheet column

    I've started with the following code that inputs the whole file into the excel spreadsheet:
    Sub Button1_Click()
    Dim strLine As String
    Dim i As Integer
    Dim intResult As Integer
    Dim strPath As String

    Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
    intResult = Application.FileDialog(msoFileDialogOpen).Show
    If intResult <> 0 Then
    strPath = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
    Open strPath For Input As #1
    i = 1
    While EOF(1) = False
    'read the next line of data in the text file
    Line Input #1, strLine
    'print the data in the current row
    Cells(i, 1) = strLine
    'increment the row counter
    i = i + 1
    Wend
    End If
    Close #1
    End Sub

  3. #3
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Open text file and copy specific rows into spreadsheet column

    Hi, larsahl,

    please add code-tags to your procedure as requested by Forum Rule #3. Thanks in advance.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  4. #4
    Registered User
    Join Date
    07-16-2014
    Location
    Sweden
    MS-Off Ver
    2010
    Posts
    7

    Re: Open text file and copy specific rows into spreadsheet column

    ok.

    now it's solved

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2505
    Posts
    27,207

    Re: Open text file and copy specific rows into spreadsheet column

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ 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: 0
    Last Post: 12-02-2013, 02:50 PM
  2. [SOLVED] Open specific folder, select file to open and copy then paste
    By Kranky in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-22-2012, 12:14 AM
  3. VBA to open an external excel file and direct to the specific spreadsheet
    By zaizhi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-22-2011, 06:36 AM
  4. Replies: 1
    Last Post: 07-30-2010, 10:01 PM
  5. Open an Excel file to a specific spreadsheet
    By Fatmosh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-26-2006, 09:20 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