+ Reply to Thread
Results 1 to 16 of 16

Trying to copy columns to a notepad text file

  1. #1
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Trying to copy columns to a notepad text file

    Hi,
    I am working on this excel sheet that I posted on this forum before.
    This time I want to use a button I created called "create a file" to
    create a new notepad file that has copied 3 columns from LC480list.
    Those columns are, "Sample Name," , "Notes," and "Sample ID".
    I want to start copy only the yellow section and paste it in a notepad file. I am not sure how to write the macro to do this. If anyone could help me that would be great. Thanks.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trying to copy columns to a notepad text file

    Hello Gamerxx13,

    This macro will copy the data highlighted in yellow to text file. Change the text file path and name to what you want.

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    Thanks for your help.
    I tried using this macro with my excel sheet and there was a debug error found, this is what it said.
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 04-18-2013 at 02:50 PM. Reason: Added Code Tags

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trying to copy columns to a notepad text file

    Hello Gamerxx13,

    That's odd. The macro worked fine for me on the workbook you posted. Is there any difference between what you posted and what you are using?

  5. #5
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    I guess I might be confused on how to assign a macro to the button. Lets see, what I did and maybe I did something incorrectly. What I did was go to the Macro button, then highlighted "SaveAsTextFile" macro, and clicked on edit. From there I went to Modules folder on the left and right click and created a new module. I renamed it FileRenaming. Then saved it, and assigned the "SaveAsTextFile" macro to the button and received that error.

    I am using the same file you were using.

  6. #6
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    Could you attach that macro to my excel sheet and it should work confirm it works correctly? Thanks.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trying to copy columns to a notepad text file

    Hello Gamerxx13,

    I have added the macro to its own module named "SavevAsTextFile". You will need to modify the file path and name in the macro to where you want the file saved and what it will be named. I have added a button and attached the macro to it.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    Hi,
    I am stil getting some errors. So When I run yours, I click on create file and get with that line in yellow:
    "Run-Time Error '1004':
    Method 'Range' of object'_Global' failed
    Please Login or Register  to view this content.
    Last edited by Leith Ross; 04-18-2013 at 04:22 PM. Reason: Added Code Tags

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trying to copy columns to a notepad text file

    Hello Gamerxx13,

    What version of Windows are you running?
    Can you post the failing workbook so I can test it on my machine?

  10. #10
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    Windows 7. Sure, but didnt I post the entire workbook earlier? Or are you not seeing code that I am seeling. Thanks. Let me know how to help.

  11. #11
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    I am a little confused on what you mean by the entire workbook? I thought I sent that to you before..maybe I am having some other files on my computer that are not being sent to you

  12. #12
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trying to copy columns to a notepad text file

    Hello

    Both workbooks appear identical. really have no idea what the problem is. The only change I made to the macro was to use the file name on sheet1. Again, it ran fine without error. Here is the code with the change...
    [
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    Hm, Im not sure, what we want to name it is as this:
    There is a file name and test file
    Name it as the text file, because I believe you can copy that.

    so it would be f7.4_b24_3021_ac_041713_n12_2.txt

  14. #14
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    What it says when I assign the Macro to the button is that this:
    Run-Time error '76':
    Path Not Found

    Sub SaveAsTextFile()

    Dim FirstCell As Range
    Dim i As Long
    Dim LastCell As Range
    Dim Rng As Range
    Dim TextFile As String

    ' Change the file path and name to what you will be using.
    TextFile = "C:\Users\Owner\Documents\" & Sheet1.Range("E11") & ".txt"

    Set FirstCell = Sheet3.Range("C2")
    Set LastCell = Sheet3.Cells(Rows.count, "C").End(xlUp)
    Set Rng = Sheet3.Range(FirstCell, LastCell).Resize(ColumnSize:=3)

    If LastCell.Row < FirstCell.Row Then Exit Sub

    Open TextFile For Output Access Write As #1
    For i = 1 To Rng.Rows.count
    Print #1, Rng.Item(i, 1), Rng.Item(i, 2), Rng.Item(i, 3)
    Next i
    Close #1

    End Sub

  15. #15
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    Sorry didnt post in yellow,
    Sub SaveAsTextFile()

    Dim FirstCell As Range
    Dim i As Long
    Dim LastCell As Range
    Dim Rng As Range
    Dim TextFile As String

    ' Change the file path and name to what you will be using.
    TextFile = "C:\Users\Owner\Documents\" & Sheet1.Range("E11") & ".txt"

    Set FirstCell = Sheet3.Range("C2")
    Set LastCell = Sheet3.Cells(Rows.count, "C").End(xlUp)
    Set Rng = Sheet3.Range(FirstCell, LastCell).Resize(ColumnSize:=3)

    If LastCell.Row < FirstCell.Row Then Exit Sub

    Open TextFile For Output Access Write As #1
    For i = 1 To Rng.Rows.count
    Print #1, Rng.Item(i, 1), Rng.Item(i, 2), Rng.Item(i, 3)
    Next i
    Close #1

    End Sub

  16. #16
    Registered User
    Join Date
    10-03-2012
    Location
    Union City, California
    MS-Off Ver
    Excel 2010
    Posts
    36

    Re: Trying to copy columns to a notepad text file

    do you know what I can do to solve this... I feel like we are close..

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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