Consulting

Results 1 to 5 of 5

Thread: Merge cells based on a cell value

  1. #1

    Merge cells based on a cell value

    I would like to merge cells C through F on each row where the value in cell A is 5. Can that be done?

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Yes.

    1.Using formulae on the worksheet or as a macro?
    2.When you say merge, merging cells in excel usually only keeps the text in the leftmost cell - do you mean concatenate? If so where do you want the result?

    the penalty for asking a brief question.. a longer response, without the solution.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3

    Merge cells based on cell value

    Thanks for the response.

    I don't want to concatentate values in cells; I actually want to merge cells C through F so they are one big cell.

    I understand that only the data in the left-most cell is retained in a merge, but in my case the merge will actually occur before any data is entered.

    I believe I will need VBA for this.

  4. #4
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    The following will work on the rows of the selected cells (the selection doesn't have to include column A) of the active sheet:
    [vba]Sub blah()
    For Each rw In Selection.Rows
    If Cells(rw.Row, 1) = 5 Then 'column A of each row
    Range(Cells(rw.Row, 3), Cells(rw.Row, 6)).Merge
    End If
    Next rw
    End Sub
    [/vba]
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  5. #5
    I got it working!

    Thanks so much!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •