+ Reply to Thread
Results 1 to 5 of 5

Copy Contents of 3 Columns into 1

  1. #1
    Registered User
    Join Date
    07-12-2005
    Posts
    2

    Copy Contents of 3 Columns into 1

    Hello
    I've got a "small" problem that has become HUGE
    I have data in 3 columns for example D E F, what i wan't to do is to move the contents of D E F into D and remove any spaces in between and do so for 10k rows or more. No problem to do manually for a few but quite hefty for 10k data posts. Someone help me writing a macro, because i'm stuck.

  2. #2
    Registered User
    Join Date
    06-09-2005
    Posts
    15
    Try this.

    Sub consolidate()

    dim totRow, a as integer
    totRow = ActiveSheet.UsedRange.Rows.Count

    For a = 1 to totRow

    Cells(a,4).Value = Trim(Cells(a,4).Value) & " " & Trim(Cells(a,5).Value) & " " & Trim(Cells(a,6).Value)

    Next

    end sub

  3. #3
    STEVE BELL
    Guest

    Re: Copy Contents of 3 Columns into 1

    This works in Excel 2000.
    The Trim() removes leading and trailing spaces
    If you are working with values than remove Trim

    [You can use Cells(), Cells().Value, Cells().Text]
    ===========================
    Dim rw as Long, x as Long

    rw = Cells(Rows.COUNT, "C").End(xlUp)

    For x = 1 to rw
    Cells(x, 4) = Trim(Cells(x, 4)) & Trim(Cells(x, 5)) & Trim(Cells(x, 6))
    Next
    ==============================
    --
    steveB

    Remove "AYN" from email to respond
    "Lynxen" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Hello
    > I've got a "small" problem that has become HUGE
    > I have data in 3 columns for example D E F, what i wan't to do is to
    > move the contents of D E F into D and remove any spaces in between and
    > do so for 10k rows or more. No problem to do manually for a few but
    > quite hefty for 10k data posts. Someone help me writing a macro,
    > because i'm stuck.
    >
    >
    > --
    > Lynxen
    > ------------------------------------------------------------------------
    > Lynxen's Profile:
    > http://www.excelforum.com/member.php...o&userid=25164
    > View this thread: http://www.excelforum.com/showthread...hreadid=386612
    >




  4. #4
    Jim Thomlinson
    Guest

    RE: Copy Contents of 3 Columns into 1

    I assume you meant in code?

    Public Sub CombineColumns()
    Dim rngCurrent As Range
    Dim wksCurrent As Worksheet

    Set wksCurrent = Sheets("Sheet1")
    Set rngCurrent = wksCurrent.Range("D65536").End(xlUp)

    Do While rngCurrent.Row > 1
    rngCurrent.Value = Trim(rngCurrent.Value) & _
    Trim(rngCurrent.Offset(0, 1).Value) & _
    Trim(rngCurrent.Offset(0, 2).Value)
    rngCurrent.Offset(0, 1).Value = ""
    rngCurrent.Offset(0, 2).Value = ""
    Set rngCurrent = rngCurrent.Offset(-1, 0)
    Loop

    End Sub
    --
    HTH...

    Jim Thomlinson


    "Lynxen" wrote:

    >
    > Hello
    > I've got a "small" problem that has become HUGE
    > I have data in 3 columns for example D E F, what i wan't to do is to
    > move the contents of D E F into D and remove any spaces in between and
    > do so for 10k rows or more. No problem to do manually for a few but
    > quite hefty for 10k data posts. Someone help me writing a macro,
    > because i'm stuck.
    >
    >
    > --
    > Lynxen
    > ------------------------------------------------------------------------
    > Lynxen's Profile: http://www.excelforum.com/member.php...o&userid=25164
    > View this thread: http://www.excelforum.com/showthread...hreadid=386612
    >
    >


  5. #5
    Registered User
    Join Date
    07-12-2005
    Posts
    2
    Thanks for the help, the first method worked great

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1