+ Reply to Thread
Results 1 to 7 of 7

VBA copy row to last cell containing a value

  1. #1
    Registered User
    Join Date
    07-20-2015
    Location
    New York, US
    MS-Off Ver
    2013
    Posts
    43

    VBA copy row to last cell containing a value

    Hi gurus,

    I am using the below code to copy a row in sheets(1) if it contains the value "BALANCE" and paste it in sheets(2).

    My issue is that it is copying the entire row, making the sheets(2) very large. I can't figure out how to only select and copy to the last used cell of the row being copied. I can't use
    Please Login or Register  to view this content.
    because there are some blanks in the row which need to be copied and pasted.

    Any help would be much appreciated! Thanks!

    Please Login or Register  to view this content.

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA copy row to last cell containing a value

    Without a sample, I'm guessing:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA copy row to last cell containing a value

    Try:
    Please Login or Register  to view this content.
    The way you have designed the code, the first time it finds "Balance" it will copy the data to Sheets(2) in H1 down the column. From then on when it finds "Balance", it will over-write the previous data in Sheets(2). I don't think that is what you want. Is it?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  4. #4
    Registered User
    Join Date
    07-20-2015
    Location
    New York, US
    MS-Off Ver
    2013
    Posts
    43

    Re: VBA copy row to last cell containing a value

    Thanks for the prompt replies xladept and Mumps1! Both of your codes are working perfectly for me with a little tweaking. Really appreciate it.

    I know my code is a bit ugly Mumps1 but it does the trick as "Balance" will only ever occur once in the sheet. Thanks for the heads up though and feel free to post how I can tidy it up you like.

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA copy row to last cell containing a value

    This code will be a little faster:
    Please Login or Register  to view this content.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA copy row to last cell containing a value

    You're welcome and thanks for the rep!

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA copy row to last cell containing a value

    Glad it worked out.

+ 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. Copy Cell Values in two Columns down x number of times then jump and copy some more.
    By scholly23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-02-2014, 03:19 AM
  2. vba to copy and insert row and copy/paste cell value if cell not blank!
    By GaryDML in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-27-2014, 02:17 AM
  3. [SOLVED] Macro to copy cell width to new sheets (ie copy original sheet format)
    By teenyjem in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-20-2013, 07:28 AM
  4. [SOLVED] How to copy data in a cell in Sheet1 to a cell in Sheet2 using =COPY( )?
    By Mr D Relf in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 07-17-2013, 10:39 AM
  5. copy a specif cell value, find another like that in sheet copy adjacent cell and pate
    By smwaqas89 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-16-2013, 10:00 AM
  6. [SOLVED] copy cell to another cell, increment and copy back.
    By Tathagata in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 04-18-2012, 07:59 PM
  7. Copy one cell to an other but colors do not copy. While not using clipboard to copy.
    By chuckchuckit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-19-2010, 03:08 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