?
Solved

Join to Excel cells using a macro

Posted on 2013-12-01
4
Medium Priority
?
109 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 49

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 2000 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 49

Expert Comment

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

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

752 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