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.
 
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!!!

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Intersect(Target, Me.Range("J15:N20")).Address = Target.Address Then
    Target.Merge
  End If
End Sub
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Mistake. Should be this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Not Intersect(Target, Me.Range("J15:N20")) Is Nothing Then
    If Intersect(Target, Me.Range("J15:N20")).Address = Target.Address Then
      Target.Merge
    End If
  End If
End Sub
 
Upvote 0
Mistake. Should be this:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  If Not Intersect(Target, Me.Range("J15:N20")) Is Nothing Then
    If Intersect(Target, Me.Range("J15:N20")).Address = Target.Address Then
      Target.Merge
    End If
  End If
End Sub

You are the man. Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,273
Members
449,219
Latest member
daynle

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