+ Reply to Thread
Results 1 to 3 of 3

VBA macro to copy last non blank cell on a certain range that has formula

  1. #1
    Registered User
    Join Date
    06-26-2015
    Location
    Brazil
    MS-Off Ver
    O365 Win
    Posts
    63

    VBA macro to copy last non blank cell on a certain range that has formula

    Hey all,

    I have asked for help on a certain task I have been trying to finish, but no luck so far, so I decided to change my logic a bit:

    I have a sheet where I fill in sales from rows 18 to 32, along with a few other cells that are always the same, and I want to copy them to a sheet called db, which is my database.

    I want to copy:
    B18 & last cell with value from B18:B32
    I18 & last cell with value from I18:I32, it has a formula that if column B is blank, they will be blank, if not $L$5+1 which is my contract number.

    Is there a code to get the last value from a range that has something written instead of a formula?
    Last edited by danwoltrs; 01-08-2016 at 02:07 PM.

  2. #2
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: VBA macro to copy last non blank cell on a certain range that has formula

    This should do it -- just change the Column and StartRow and MyShtName name to appropriate values for your workbook.

    Please Login or Register  to view this content.
    To clarify, what that does is puts the cells you'll want to copy into a range variable. If you want the last row b/f you get to a formula, you can execute: rngToCopy.Cells.SpecialCells(xlCellTypeLastCell).Row, but I thought you'd want it in a range variable so you can easily execute: rngToCopy.Copy.

    Also note that if you have in column 1 (with the code above, in sheet name specified in the above code):
    row 1: 3
    row 2: "hello world"
    row 3: 4
    row 4: 42
    row 5: =A4-A3
    row 6: 7
    row 7: =A6-A3
    .
    .
    .
    ...the rngToCopy will contain rows 2 thru 4 in column 1 (because the StartRow = 2 and the range contains all cells between StartRow and the end of the CONSECUTIVE (if there is a space, the row b/f the space will be the last cell in the range) rows that contain NO FORMULA.

    I can help with any modifications.
    Last edited by joe31623; 01-08-2016 at 02:37 PM.
    <---If my answer helped, please click *

  3. #3
    Registered User
    Join Date
    06-26-2015
    Location
    Brazil
    MS-Off Ver
    O365 Win
    Posts
    63

    Re: VBA macro to copy last non blank cell on a certain range that has formula

    Hey Joe, thanks for helping - would you mind checking my workbook, I have not been able to get it to work with your macro above.

    Also, I would need to copy two columns, not one. If you could kindly check my workbook and see where I have failed? :D
    Attached Files Attached Files

+ 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] Macro to copy and paste new data into the next blank cell WITHIN a range
    By MattRNR in forum Excel Programming / VBA / Macros
    Replies: 32
    Last Post: 10-22-2015, 12:45 AM
  2. [SOLVED] Macro or Formula to Copy Value in Next Available Blank Cell
    By jeversf in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-06-2014, 08:53 PM
  3. macro to copy changing range to next blank cell in another sheet
    By d2whales in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-09-2013, 12:55 PM
  4. [SOLVED] Macro to copy a cell range and paste to a new sheet 'n' times where 'n' defined by formula
    By staminaboy in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-26-2013, 11:39 AM
  5. [SOLVED] Macro to copy formula to blank cells in a dynamic range
    By masben in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-25-2013, 07:07 AM
  6. [SOLVED] Copy data from a range of cells into a blank range based on common cell
    By vanmeterkj in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-03-2012, 10:18 AM
  7. formula/macro to colour blank cell in a range
    By EAMOG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-29-2010, 04:17 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