Solved

Join to Excel cells using a macro

Posted on 2013-12-01
4
106 Views
Last Modified: 2014-06-15
Hello Experts Exchange
I had a interview test and one of the questions was to combine two Excel cells one called forename the other called surname in to one cell using a macro.  Is this possible to do using a macro and if so can you tell me the steps on how to make the macro work please?

Regards

SQLSearcher
0
Comment
Question by:SQLSearcher
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39688097
Record a macro while doing it manually and you will have the macro you need.
0
 
LVL 6

Accepted Solution

by:
ButlerTechnology earned 500 total points
ID: 39688245
Are you sure it was a macro and not a formula?  I have written that formula many times.
I could see a macro creating a third column with forename and surname being concatenated together and then removing the two original columns.

This code assumes two columns Forename and SurName.  It will create a label in the third column and then loop thru the names while putting the forename and surname in the third column.
Public Sub FullName()
ActiveCell.Offset(0, 2).Value = "Full Name"
ActiveCell.Offset(1, 0).Activate
Do
  ActiveCell.Offset(0, 2).Value = ActiveCell.Value & " " & ActiveCell.Offset(0, 1).Value
  ActiveCell.Offset(1, 0).Activate
Loop Until IsEmpty(ActiveCell)
End Sub

Open in new window


Tom
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39688528
You could use something like this

Sub combine1st2nd()
    Dim cel As Range
    For Each cel In Range("A1:A" & Range("A1").End(xlDown).Row)
        cel.Value = cel.Value & " " & cel.Offset(, 1).Value
        cel.Offset(, 1).ClearContents
    Next cel
End Sub
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39701163
Did any of the above help you?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question