+ Reply to Thread
Results 1 to 9 of 9

VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

  1. #1
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    Hi, I wonder whether someone may be able to help me please.

    I'm using the code below to find the LastRow and apply formatting to two non contiguous rows with differing lengths columns, but on the same sheet.

    Please Login or Register  to view this content.
    The code works fine, but I'm aware it's a little cumbersome.

    Could someone possibly tell me please, is there a way that these could be amalgamated.

    I have searched for this, but all the examples I've found don't apply to 'non-contiguous' ranges or are unsuitable.

    Many thanks and kind regards

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    You can combine the code by using a Union range and working on the Areas.
    Whether it makes the code less cumbersome I'm not sure.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    Try this...


    Please Login or Register  to view this content.
    Cheers!!

  4. #4
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    Hi Andy, thank you once more, for taking the time to reply to one of my post and for the code.

    I'd not even heard of the 'Union' function, but this is really very useful and works great.

    All the best and kind regards

    Chris

  5. #5
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    Hi @excelliot, thank you for taking the time to come back to me with this and the time in putting together the code which works very well!

    All the best and kind regards

    Chris

  6. #6
    Forum Contributor
    Join Date
    06-24-2005
    Location
    excelliot.com
    MS-Off Ver
    2007
    Posts
    325

    Re: VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    Cheers!!

  7. #7
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    Hi, I wonder whether someone may be able to help me please.

    With some adaptation, I using the code kindly provided by Andy Pope to apply formatting and sorting to multiple ranges of differing lengths. The code I've put together is as below:

    Please Login or Register  to view this content.
    The problem I have is that the number format is not being applied to all the cells in column F even though it is not at the beginning or end of the ranges.

    The difficulty I have in understanding this that column F is shorter than column Q for example, yet this column is corrected formatted.

    I just wondered whether someone may be able to look at this please and let me know where I'm going wrong.

    Many thanks and kind regards

    Chris

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    You only have 1 LastRow value. In your code this would mean all the blocks go from row 10 to whatever is the last row in column B.
    Don't you want varying lengths?

    Please Login or Register  to view this content.
    In the attached. Use Test1 to format Sheet1. This is your original code and highlights the problem about which cells are actually part of the Union.

    On Sheet2 the same information can be formatted by using revised Test2 routine.

    Only issue then is what range should actually be sorted? Currently only column B and C are sorted.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    05-26-2012
    Location
    United Kingdom
    MS-Off Ver
    Excel 2013
    Posts
    682

    Re: VBA Find LastRow Of Multiple Non Contiguous Columns On One SHeet

    Hi Andy, thank you for coming back to me with this, I really appreciate it.

    I also thank you for the explanation.

    I actually thought it was this piece of code which controlled the range "Range("Q10:R" & Cells(Rows.Count, "Q").End(xlUp).Row))" because of the 'Union' function and because all of the other columns in the whole range, with some columns shorter and longer than column B were correctly formatted, oh how I was wrong. I can confirm that the second script is what I was after and works great!

    Once again many thanks for your help and kind regards

    Chris

+ 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] How to sum non-contiguous columns applied as a formula on contiguous cells
    By figo12 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-09-2013, 01:07 PM
  2. [SOLVED] How to delete multiple contiguous (and/or) non-contiguous rows, in an excel table
    By jimmalk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-03-2012, 05:48 AM
  3. Replies: 0
    Last Post: 08-03-2012, 04:31 PM
  4. find averages not including 0's for values not in contiguous rows or columns
    By jrozendaal in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-14-2005, 11:10 PM
  5. [SOLVED] How do I reference non-contiguous columns in another sheet and th.
    By Bill Nash in forum Excel General
    Replies: 3
    Last Post: 03-03-2005, 02:06 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