Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel 2007 macro to merge cells

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I want to highlight a few cells and merge them
I recorded this macro which has cell selection embedded in it.
How to I change it so that it takes the cells I currently have highlighted and merges them

Code:
    Range("J8:K8").Select   ' change this to my selection
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = True
    End With
TIA


DougP
[r2d2] < I Built one
 
wow I stumbled on this mby accident
I just removed the reference and it works
Code:
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = True
    End With
[code]

so "With Selection" knows what I have highlighted 


DougP
[r2d2] < I Built one
[URL unfurl="true"]www.robots2000.com[/URL]
 



Doug,

You've been around long enough to know that VBA questions are best addressed in forum707 AND that we discourage such postings in this forum.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top