Solved

Join to Excel cells using a macro

Posted on 2013-12-01
4
102 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
  • 2
4 Comments
 
LVL 46

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 46

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now