+ Reply to Thread
Results 1 to 2 of 2

merge cells with macro

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

    merge cells with macro

    I am trying to format and merge 4 cells within a macro as follows:

    Range("E20:E23").Select
    With Selection
    .HorizontalAlignment = xlGeneral
    .VerticalAlignment = xlBottom
    .WrapText = True
    .Orientation = 0
    .AddIndent = False
    .ShrinkToFit = False
    .MergeCells = True
    End With
    Range("F20:F23").Select
    With Selection
    .HorizontalAlignment = xlGeneral
    .VerticalAlignment = xlBottom
    .WrapText = True
    .Orientation = 0
    .AddIndent = False
    .ShrinkToFit = False
    .MergeCells = True
    End With
    End Sub

    The problem I have is that the range of cells are different each time (i.e. tommorrow the cells may be "E30:E33" & "F30:F33". In other words, I want the merge to occur in the cell active cell I have selected. So if my cursor is in the current cell of "B22" that is where I want the merge to begin.

    Thank you in advance for any comments.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Try

    This code selects 3 columns to the right of the active cell
    Merges Cells
    Repeats for row below active cell


    Sub RangeSelect()
    ActiveCell.Resize(1, 3).Select
    Call MergeCells
    ActiveCell.Offset(1, 0).Resize(1, 3).Select
    Call MergeCells
    End Sub


    Sub MergeCells()
    With Selection
    .HorizontalAlignment = xlGeneral
    .VerticalAlignment = xlBottom
    .WrapText = True
    .Orientation = 0
    .AddIndent = False
    .ShrinkToFit = False
    .MergeCells = True
    End With
    End Sub

+ 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