Solved

Concatinate and Trim Column A and B

Posted on 2011-09-13
6
260 Views
Last Modified: 2012-05-12
I am looking for a macro that will work with column A and B.  First I would like to concatenate column A with column B, however column B has unwanted spaces in it, so I need to TRIM out or CLEAN column B either before or after.  Is there an easier way to do this by the column instead of having to copy the formula down and copy/paste specail values etc.  There is no set number of rows, which can change from day-to-day.

Would like to automate this.  Please advise and thanks. -R-
0
Comment
Question by:RWayneH
[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
  • 4
  • 2
6 Comments
 
LVL 13

Expert Comment

by:nike_golf
ID: 36530918
This is quick and dirty but you get the idea. The concatenated item is placed in column "C", this also assumes there are no blank rows in colum "A".

Public Sub concat()
Dim rng, x As Range

Set rng = ActiveSheet.Range("a1", Range("A1").End(xlDown))

For Each x In rng
    x.Offset(0, 3) = x & Trim(x.Offset(0, 1))
Next x

End Sub

NG,


0
 
LVL 13

Expert Comment

by:nike_golf
ID: 36530923
Sorry the answer is put in column "D"... and can be adjusted by the x.Offset(0, 3)

NG,

0
 

Author Comment

by:RWayneH
ID: 36531101
Sorry, I forgot to ask....  Is there a way to put a hyphen between the values in Col A and Col B?  -R-
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 13

Accepted Solution

by:
nike_golf earned 500 total points
ID: 36531187
Public Sub concat()
Dim rng, x As Range

Set rng = ActiveSheet.Range("a1", Range("A1").End(xlDown))

For Each x In rng
    x.Offset(0, 3) = x & " - " & Trim(x.Offset(0, 1))
Next x

End Sub

NG,
0
 

Author Closing Comment

by:RWayneH
ID: 36531400
This is an EXCELent and very flexible solution.  Thanks. -R-
0
 
LVL 13

Expert Comment

by:nike_golf
ID: 36531730
Glad I could help.

NG,
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

724 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