+ Reply to Thread
Results 1 to 6 of 6

Find last row, copy, paste works but a little help with cleaning up the code

  1. #1
    Registered User
    Join Date
    05-27-2013
    Location
    BEDS
    MS-Off Ver
    Excel 2003
    Posts
    44

    Find last row, copy, paste works but a little help with cleaning up the code

    Hi there,

    So I've spent most of this evening learning VBA to expand my knowledge. I am trying to do a simple everyday task and not sure if there is a quicker way of doing this...

    1) Data is in Cell A2 onwards
    2) Formula is in B1 and C1
    3) Formula is to concatenate B1 and A1 to go down to the bottom of the data set in Cell A
    4) Column C is to do the same
    5) Copy Column C data into Column B (start at the end of the data set) and then pastevalues
    6) Copy and paste the data into a notepad and then save.

    I think I'm using to much LastRow / FindLastRow etc... but I can't seem to re-use them as it doesn't seem to re-look at the data set again to copy the new information or view the next lastrow...
    Also I've noticed when it copies and pastes it repeats the paste of B2 - B6 (as an example) but in the notepad it copies fine... The issue is that I will probably have around 30-40 thousand rows of data in cell B before I even copy the data in cell C so it could take a little bit of time...

    I've blocked out the copy/paste and save to note pad as was testing, this is working fine, although I am trying to read up how to actually save it to a desktop. Eventually I will be saving it to a shared location but will also want to label it to the date (YYYYMMDD - Name of file.txt)

    Is there any help on this please or any way to simplify it.

    Please Login or Register  to view this content.
    Thanks

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Find last row, copy, paste works but a little help with cleaning up the code

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 11-16-2017 at 07:06 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    05-27-2013
    Location
    BEDS
    MS-Off Ver
    Excel 2003
    Posts
    44
    Quote Originally Posted by mehmetcik View Post
    Please Login or Register  to view this content.
    Wow thanks, looks alot neater i will gove this a try tomorrow as ive only just turnt my computer off and let you know how i get along. Thank you again

  4. #4
    Registered User
    Join Date
    05-27-2013
    Location
    BEDS
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Find last row, copy, paste works but a little help with cleaning up the code

    Please Login or Register  to view this content.
    Morning, thank you for your help, the clean up code has lost a few elements when trying to run this.
    There is a formula in both B1 and C1 that needs to go to the bottom of the data set. The cleaned up version only copies the formula in B1 and not the one in C1. Also when it opens the notepad, it doesn't copy the data in from B1 (it may reads 1 character of 1 line and sometimes brings a full second line back).
    For me the most important part was being able to do the following:

    1) Copy the formula in B1 to the bottom of the data set (formula is $B$1&$A1)
    2) Find the last empty row in column B where the formula has been copied
    3) Copy the formula in C1 to the bottom of the data set (formula is $C$1&$A1)
    4) Select all the values from B2 downwards
    Also when copying to notepad, it does seem to copy the first formulas in the B1 - B5 (as an example).

    I've attached the spreadsheet (it's only a test version as the main one will have lots of data in cell A) if it helps. I was trying to understand if there was a way to clean up the code or if my version of the code had to many different lastrow elements.
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Find last row, copy, paste works but a little help with cleaning up the code

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-27-2013
    Location
    BEDS
    MS-Off Ver
    Excel 2003
    Posts
    44

    Re: Find last row, copy, paste works but a little help with cleaning up the code

    Hey thank you for your help mehmetcik - the code clean up was great. I made a few more tweaks so that I was able to save this automatically. I removed the notepad option and ended up opening a new worksheet and saving the values there and then saving that as a .txt file which works alot better.

+ 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] text from mail copy paste , cleaning
    By makinmomb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-12-2014, 11:48 PM
  2. Search, find, copy and paste macro or code.
    By andrew0789 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-10-2014, 03:01 AM
  3. [SOLVED] Trying to find the right code to copy a column from one worksheet and paste to another
    By mw91 in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 11-15-2013, 01:57 PM
  4. Code: Find, Copy, Paste not working
    By ufopilot3 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-26-2012, 03:40 PM
  5. Help with find, copy, and paste code using offset
    By mundellj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-28-2011, 08:16 PM
  6. code to find, copy and paste until find new, then repeat
    By siddharthariver in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2010, 04:02 PM
  7. [SOLVED] code to FIND value, copy, paste values onto other sheet
    By ufo_pilot in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-06-2005, 12:20 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