+ Reply to Thread
Results 1 to 10 of 10

Copy Visible Range in Excel and Paste into Text File

  1. #1
    Registered User
    Join Date
    11-30-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Copy Visible Range in Excel and Paste into Text File

    I have looked all over the forums and could not find specific code to do exactly this (only pieces of code that probably put together would do what I want).

    Would it be possible to do the following:
    •Filter Column B of Sheets("Test1") for word "R/R" -- this sheet pulls its data from an external access query and is setup as a table (not sure if this matters)
    •Copy Visible cells in Column P
    •Paste as is to a text file in a specific destination (By as is I mean how it would look if you manually copied and pasted the cell range into a text file)

    I wanted to do this with the Write or Print and not simply copy to the clipboard and paste.

    Please see below for my code. It filters and copies/pastes to the desired text file however it stops at the first filtered cell, i.e. there are 5 rows with "R/R" in column B (571,4213,4510,5191,5192), but it only pastes cell P571.



    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jpv5; 09-07-2016 at 03:00 PM.

  2. #2
    Registered User
    Join Date
    11-30-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Copy Visible Range in Excel and Paste into Text File

    Hello, thank you for the quick reply. I have gone ahead and added the code/code. I figured that what I am trying to do is self-explanatory and wouldn't need to attach a spreadsheet. I just want the macro to:

    1) Filter column B
    2) Copy all contents that are visible in column P of Sheets("Test1") -- this sheet pulls its data from an external access query and is setup as a table (not sure if this matters)
    3) paste to a text file in a designated location.

    I am not really sure how to show the process for before/after on spreadsheet since there will be two different files (the macro, and the text file -- hopefully my explanation is understandable). Thanks again.
    Last edited by jpv5; 09-07-2016 at 01:39 PM.

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,613

    Re: Copy Visible Range in Excel and Paste into Text File

    Thanks for adding code tags. As for before/after: input file and expected output will fill the scene with light :-)
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    11-30-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Copy Visible Range in Excel and Paste into Text File

    Hello, thanks again for the quick reply! I attached 2 files (spreadsheet filtered and where the data should be pulled/copied from and the text file for how it should be pasted/formatted).

    Thanks!

  5. #5
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Copy Visible Range in Excel and Paste into Text File

    Welcome to the forum! Pls take some minutes to read forum rules because(in this case..).
    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).


    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  6. #6
    Registered User
    Join Date
    11-30-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Copy Visible Range in Excel and Paste into Text File

    Hello -- I figured that the other post on that website was closed (on hold). I went ahead and deleted the post from stackoverflow.com (no responses were given).
    Please re-open this thread thank you.

  7. #7
    Registered User
    Join Date
    11-30-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Copy Visible Range in Excel and Paste into Text File

    any help with above? thanks!

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Copy Visible Range in Excel and Paste into Text File

    Replace myrng.Rows.Count with myrng.Cells.Count and see if that works.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  9. #9
    Registered User
    Join Date
    11-30-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Copy Visible Range in Excel and Paste into Text File

    Hi sktneer thanks for the response, hwoever changing myrng.Rows.Count with myrng.Cells.Count makes it pull the first unfiltered cell (which is correct), and then the following number of cells (filtered). I.e. if there are 10 cells in Column B with "R/R", it pulls 10 cells in column P starting from the first one with R/R in cell B. Therefore, if B4 = R/R, it will copy text in P4, and P5,6,7,8,9,10,11,12,13 (even if only B6 and B9 have "R/R"). In other words, it is picking up the correct amount of cells, but including filtered ones too, not just the unfiltered with "R/R" in Column B

  10. #10
    Registered User
    Join Date
    11-30-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Copy Visible Range in Excel and Paste into Text File

    Hello Kaper, would you happen to have a suggestion? Thanks! Really need this for work.

+ 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. [SOLVED] Copy same range in many excel files and paste into a main file
    By dualaudio454252 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-15-2014, 05:25 PM
  2. Replies: 5
    Last Post: 10-28-2014, 01:55 PM
  3. macro to copy used range and paste in the body tag of a html file/text file
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2014, 08:34 PM
  4. Macro to copy the range of values from Excel and paste in html file
    By harishpeddi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-25-2014, 10:50 AM
  5. [SOLVED] Range Selection up to last visible adjacent cell,filter,copy paste to next sheet
    By kcube17 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2013, 07:08 AM
  6. [SOLVED] Unable to copy and paste a text file into excel
    By Jack40 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-23-2012, 10:53 PM
  7. Vba code to copy and paste second visible cell to other worksheet range then the next
    By Justin25150 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2012, 09:03 AM

Tags for this Thread

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