+ Reply to Thread
Results 1 to 9 of 9

Macro to Combine a List if the adjacent cells are blank

  1. #1
    Registered User
    Join Date
    04-29-2016
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    6

    Macro to Combine a List if the adjacent cells are blank

    Hello,

    I need to create a macro that will combine a list of cells in column B, into another single cell (column C), with the data separated by "||", if the adjacent cells (column A) are blank.

    See attached pics for what it should look like before and after running the macro.

    I have tried a few things, but none have worked as I only have a basic understanding of macros so I am not sure how else to go about this. Any ideas?
    Thanks.
    Attached Images Attached Images

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro to Combine a List if the adjacent cells are blank

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-29-2016
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    6

    Re: Macro to Combine a List if the adjacent cells are blank

    Works great Thanks.
    Now, if I wanted to have the combined cell (column C) populate onto another worksheet, how would I do that?
    So the original list is on worksheetA, but I want the list compiled in worksheetB (instead of in column C)

    Edit:
    My actual spreadsheet, the "columnA" data is actually in column D and the "column B" data is actually in column Q.
    I can't show a screen though as it contains sensitive information.
    So basically I need the column Q list to compile if the column D is blank, and then I need the combined data to show up on worksheetB.
    I tried manipulating the macro you provided but not sure what the offsets etc would be. Thoughts?
    Last edited by moodle; 04-29-2016 at 04:20 PM.

  4. #4
    Registered User
    Join Date
    04-29-2016
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    6

    Re: Macro to Combine a List if the adjacent cells are blank

    bump, see post above.

    If it cannot be copied to the other worksheet (worksheetB, column G), if the data could populate into column R (on the same worksheetA) that would work too.
    I can't get the columns D and Q to work though, I think it is combining column E and populating to column F. But I need it to combine column Q and populate to column R (if column D is blank).

    EDIT:
    I did this and it now combines to column R correctly:

    Dim rngArea As Range
    For Each rngArea In Range("D2:D" & Range("Q" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeBlanks).Areas
    Set rngArea = rngArea.Offset(-1, 13).Resize(rngArea.Count + 1)
    rngArea(1).Offset(, 1).Value = Join(Application.Transpose(rngArea), "||")
    Next rngArea
    Columns("R").AutoFit


    BUT I get an error - Runtime Error '13': Type Mismatch for this line:

    rngArea(1).Offset(, 1).Value = Join(Application.Transpose(rngArea), "||")

    So it works technically but I will have more lines after this so it doesn't help if it errors.
    Last edited by moodle; 05-02-2016 at 02:58 PM.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro to Combine a List if the adjacent cells are blank

    Your modified code looks correct. Apparently there is some issue with the data configuration, but I don't know what it is. If you could post a desensitized copy of the workbook that still errors, I'll take a look.

    If you want the results on worksheetB;
    then in what column?
    do you want the results in consecutive rows?

  6. #6
    Registered User
    Join Date
    04-29-2016
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    6

    Re: Macro to Combine a List if the adjacent cells are blank

    I thought I might be able to give you a desensitized copy, but there are a lot of features built in, containing sensitive info, that if I removed them I don't think the workbook would even work properly to show you the error. I will try and figure out a way, if not I'll just try to figure out the error myself I guess. I'll get back to you.

  7. #7
    Registered User
    Join Date
    04-29-2016
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    6

    Re: Macro to Combine a List if the adjacent cells are blank

    Ok I figured it out, in my Q column I have a formula to combine cell data, but there isn't always data if the cells are blank, so looks like it just couldn't handle that much "blank" data formulas? Once I removed the unnecessary data it worked with no errors.

    I have something else now to add. Basically I have column G and H. I need to copy the data from column G to the adjacent cell in column H only if the cell in column H is blank. Then column G can be deleted. See pic for example.

    I can only manage to get the column G values to paste below the last value in column H, not in the adjacent cell. So right now my column H looks like this:
    ...
    Site4
    (blank)
    Site5
    Name3
    Name5
    Name7

    which is not correct.
    Attached Images Attached Images

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Macro to Combine a List if the adjacent cells are blank

    New questions should probably have their own thread.

    Try something like this. It assumes the blank cells in column H are truly blanks and not null string results from formulas.

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    04-29-2016
    Location
    Canada
    MS-Off Ver
    2007
    Posts
    6

    Re: Macro to Combine a List if the adjacent cells are blank

    You are awesome! Thank you so much! This has definitely made things a lot easier and will save me a bunch of time. Occasionally I have 250+ records to go through and combine them and it was taking me forever.

+ 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] Find last max. value in list and count all previous non-blank cells in adjacent column
    By zeegerman in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-25-2015, 05:01 PM
  2. [SOLVED] Macro to combine cells in a row to 1 cell while skipping blank cells
    By ywang in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-18-2014, 10:39 AM
  3. [SOLVED] Macro to combine cells in a row to 1 cell while skipping blank cells
    By ywang in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-02-2014, 07:41 PM
  4. Auto fill macro when adjacent column has blank cells
    By ElsiePOA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-30-2014, 09:49 PM
  5. [SOLVED] Code to list cells with adjacent blank cell in userform listbox.
    By Nitefox in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 6
    Last Post: 12-24-2013, 10:27 PM
  6. Combine text in multiple cells if adjacent column is blank
    By problematic in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2012, 01:52 PM
  7. Replies: 4
    Last Post: 01-05-2011, 11:37 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