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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VBA to Merge Two Cells

Status
Not open for further replies.

CMichaelW

Technical User
Jun 20, 2006
2
US
I am attempting to include some code in a procedure I have been developing, but I get errors with all the interations I have tried to use. The cells are A1:B1.

I have used the following code:

Range("A1:B1").Select
' Range("B1").Activate (commented out for testing)
Selection.MergeCells

I have also used Selection.Merge in the 3rd line. I have used the Macro Recorder and it has generated code using both Selection.MergeCells and Selection.Merge.

Do not find much info using web searchs and search of this site.

This should be fairly simple, but I am stumped at this point.

Thanks for any help!


CMW
 
CMichaelW,
This works in Excel 2k SR1.
[tt]Range("A1:B1").MergeCells = True[/tt]

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
CautionMP,

Thanks for your help - it worked!


CMW
 
Unless you have a very good reason for merging cells you should avoid doing so.

Merged cells screw up many useful features of Excel.

If you just want some text or a formula result to display across the range use center across selection instead.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top