Consulting

Results 1 to 3 of 3

Thread: Combining two cells into One

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Combining two cells into One

    I don't believe I have seen the code for this anywhere but if someone knows where it might be let me know.

    I have two cells that have a last name and a first name in them. I need to combine them into one cell, last name then a space then the first name. If anyone has any ideas please let me know. Thanks

  2. #2
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Hey,

    You could use something like this ...

    Option Explicit
    
    Sub CreateFullName()
        Dim cel As Range, rng As Range
        Set rng = Range("A2:A10")
        For Each cel In rng
            cel.Offset(, 2).Value = cel.Value & " " & cel.Offset(, 1).Value
        Next cel
    End Sub

    This is assuming some things. 1) Your range of Last Names are in A2:A10. 2) Your first names are in the corresponding rows in column B. 3) You have nothing in the corresponding rows of column C as that's where the concatenated values go. A formula would look like ...


    =A2&" "&B2

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    A possibly faster way also ...


    Option Explicit
    
    Sub CreateFullName()
        With Range("C2:C10")
            .FormulaR1C1 = "=RC[-2]&"" ""&RC[-1]"
            .Value = .Value
        End With
    End Sub
    Making the same assumptions..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •