Merge Cells

craigwojo

Active Member
Joined
Jan 7, 2005
Messages
279
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I need to merge cells with data in each cell and need to put an "-" in between the cell data.

Example:

Cell A1: PN01
Cell B1: V108a

I need the cell (one cell) to look like: PN01 - V108a. I have thousands of these and do not want to re-type them.

Thank you,
Craig
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
But that's not actually merging the cells, it's just a formula that will put the dash between the two. If you actually need the cells merged, a macro would be better and accomplish what was described. I got tired of having to go through the menus each time to merge cells and eventually made a small routine with a shortcut key to merge whatever cells I had selected, so I know this is not very difficult to do with code.
 
Upvote 0
Hi Craig

If you really, really want to merge the cells then you could try this:

Code:
Sub test()
Dim v As Variant, i As Long, r As Range
Application.DisplayAlerts = False
Set r = Selection
v = Selection.Value
For i = 1 To UBound(v, 1)
    With r(i, 1).Resize(, 2)
        .Merge
        .Value = v(i, 1) & " - " & v(i, 2)
    End With
Next i
End Sub


Select the two columns of data eg A1:B1000 first before you run it.
 
Upvote 0

Forum statistics

Threads
1,225,563
Messages
6,185,698
Members
453,315
Latest member
funktgf

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