+ Reply to Thread
Results 1 to 3 of 3

Ignore empty cells when doing horizontal sort with VBA

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,176

    Ignore empty cells when doing horizontal sort with VBA

    I am trying to do a horizontal sort for 6 columns of data per row. I then want to concat all 6 columns into one single cell. The VBA code I am using works fine except for a situation in which there is an empty cell between two columns of data.

    As per the example below, code works fine for first two records. I get a run-time error at the third record because the cell in second column is blank. (sample attached with expected results, if needed). Thanks

    Column 1.........Column 2..............Column3..........Expected Result
    2222...............5555.............................................22225555
    5555...............2222.............................................22225555
    5555............................................2222................22225555

    Please Login or Register  to view this content.
    For example:
    Attached Files Attached Files
    Last edited by maacmaac; 02-17-2012 at 10:50 PM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Ignore empty cells when doing horizontal sort with VBA

    hi maacmaac, please check attachment, I've changed it slightly
    Attached Files Attached Files

  3. #3
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Ignore empty cells when doing horizontal sort with VBA

    You only have to change this line of code:

    Please Login or Register  to view this content.
    You don't have to resize the range.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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