Merge two cells in Excel
Thread poster: Hans Lenting
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
Mar 28

I'm looking for a macro to merge two adjacent cells either horizontally or vertically. The contents of the cells should be separated by a space character:

Screenshot 2024-03-28 at 14.27.04

Desired result
A1 becomes A1+space+A2
B3 becomes B3+space+B4



[Edited at 2024-03-29 08:25 GMT]


 
Dan Lucas
Dan Lucas  Identity Verified
United Kingdom
Local time: 18:16
Member (2014)
Japanese to English
Seems simple enough Mar 28

You mean in Excel, right. Something like this?

Sub Macro1()
Application.DisplayAlerts = False
NewString = Selection.Cells(1).Value & " " & Selection.Cells(2).Value
'Debug.Print NewString
Selection.Merge
Selection.Value = NewString
'Application.DisableAlerts = True
End Sub

On your final use you probably want to set to true again.

Dan


Hans Lenting
 
Hans Lenting
Hans Lenting
Netherlands
Member (2006)
German to Dutch
TOPIC STARTER
Thanks Mar 29

Thank you, Dan! You put me on the right track. This is what I needed:
Screenshot 2024-03-29 at 09.19.00


Dan Lucas
 
Dan Lucas
Dan Lucas  Identity Verified
United Kingdom
Local time: 18:16
Member (2014)
Japanese to English
VBA FTW Mar 29

Glad it's working for you. I think it's wise to avoid merge if you can, and as you clearly have, as structural changes like that can mess up your worksheet pretty quickly.

I know it's fashionable to look down on things like VBA, but it's actually a very practical and handy language if you are working in Office a lot.

Dan


Hans Lenting
 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Merge two cells in Excel






Trados Studio 2022 Freelance
The leading translation software used by over 270,000 translators.

Designed with your feedback in mind, Trados Studio 2022 delivers an unrivalled, powerful desktop and cloud solution, empowering you to work in the most efficient and cost-effective way.

More info »
TM-Town
Manage your TMs and Terms ... and boost your translation business

Are you ready for something fresh in the industry? TM-Town is a unique new site for you -- the freelance translator -- to store, manage and share translation memories (TMs) and glossaries...and potentially meet new clients on the basis of your prior work.

More info »