Select a range of cells with the cursor then have those cells merge

Edward Sky

New Member
Joined
Jul 8, 2017
Messages
24
I'm looking for a vba solution. The reason I need to merge cells is to give me a final picture of what an end product would look like without manually selecting a range, pressing merge and center and then selecting another range etc... Is this possible?

Thank you.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hello, this would go in the code module for the sheet:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Target.Merge
End Sub
 
Upvote 0
Maybe this. Where you would select the cell with the "text" or what ever and run the snippet.

This does not MERGE. it Centers Across Selection, with the "selection" being 1 row by 6 columns.

There are good reasons to avoid "merged" cells.

Howard

Code:
Sub Center_Me()
   With ActiveCell.Resize(1, 6)
     .HorizontalAlignment = xlCenterAcrossSelection
     .VerticalAlignment = xlBottom
    End With
End Sub
 
Upvote 0
Code:
Sub SelectAndMerge()
Dim R As Range
On Error Resume Next
Set R = Application.InputBox("Select a contiguous range of cells to merge", Type:=8)
If R Is Nothing Then Exit Sub
If R.Areas.Count > 1 Then
    MsgBox "Selection must be a single contiguous range - goodbye"
    Exit Sub
End If
With R
    .Merge
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
End With
End Sub
 
Last edited:
Upvote 0
Hello, this would go in the code module for the sheet:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Target.Merge
End Sub

This was exactly what I was looking for.

One last thing, Is there a way for this to be restricted to a specific range of cells say from J15:N20?
That would be the incredible.
Thank you!!!
 
Upvote 0
Silly question but why do you need to merge the cells and are they on the same row?
Because if the solution by L Howard works for you then I would totally avoid merged cells.
 
Upvote 0
Silly question but why do you need to merge the cells and are they on the same row?
Because if the solution by L Howard works for you then I would totally avoid merged cells.

Oh! Well umm. My friend works with making windows for a living, and because customers want different patterns made up within their window space, it's necessary to replicate that pattern on the spreadsheet to work out both the size of the glass that needs to be cut, and the amount of framework needed for the job. I wish I could attach a picture but I'm relatively new to forums and don't know how.
 
Upvote 0
How do you get an accurate measurement using merged cells :eeek:
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top