Solved

Join to Excel cells using a macro

Posted on 2013-12-01
4
101 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 45

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 45

Expert Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

762 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

20 Experts available now in Live!

Get 1:1 Help Now