+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    01-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Smile Move Text dynamically to another cell

    Hi everyone!
    FIRST OF ALL AND FOREMOST HAPPY NEW YEAR!!!
    I would need help with the following:


    I have an excel sheet with about a thousand company addresses that should be on the following format1
    Column A
    Companyname
    Street Address
    City
    State Zip COde


    Right now, the document looks like this: format2:
    ColumnA ColumnB ColumnC ColumnD ColumnE
    Companyname StreetAddress City State Zipcode


    SO I would like to copy for each row all the cells B,C,D,E underneath column A
    to make it looks like the format 1 above
    I would need to skip a line underneath each address as well.
    Thank you very much!
    Help as soon as possible if possible
    HAPPY NEW YEAR
    Last edited by st4more; 01-03-2010 at 04:30 PM. Reason: Solved by JBeaucaire !!

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Moving Text dynamically to another cell

    This should do it, it will create the new list for you in column H:
    Code:
    Option Explicit
    
    Sub ReformatAddresses()
    'Author:    JBeaucaire
    'Date:      1/3/2010
    'Convert row format addresses into columnar format
    Dim LR As Long, i As Long
    Application.ScreenUpdating = False
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 1 To LR
        Range(Cells(i, "A"), Cells(i, "E")).Copy
        Range("E" & Rows.Count).End(xlUp).Offset(2, 0).PasteSpecial xlPasteAll, , , True
    Next i
    
    Range("E1:E2").Delete xlShiftUp
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    01-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Moving Text dynamically to another cell

    HI
    Thank you for your speedy response.
    However there seems to be a slight mistake I think as the compiler tells me that a variable is not defined...
    thank you.

  4. #4
    Registered User
    Join Date
    01-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Moving Text dynamically to another cell

    Quote Originally Posted by JBeaucaire View Post
    This should do it, it will create the new list for you in column H:
    Code:
    Option Explicit
    
    Sub ReformatAddresses()
    'Author:    JBeaucaire
    'Date:      1/3/2010
    'Convert row format addresses into columnar format
    Dim LR As Long, i As Long
    Application.ScreenUpdating = False
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 1 To LR
        Range(Cells(i, "A"), Cells(i, "E")).Copy
        Range("E" & Rows.Count).End(xlUp).Offset(2, 0).PasteSpecial xlPasteAll, , , True
    Next i
    
    Range("E1:E2").Delete xlShiftUp
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub
    --------------------------------------------------------------------------------

    HI
    Thank you for your speedy response.
    However there seems to be a slight mistake I think as the compiler tells me that a variable is not defined...
    thank you.

  5. #5
    Registered User
    Join Date
    01-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Moving Text dynamically to another cell

    HI
    Thanks a lot. it worked in fact. I was using it in OpenOffice and it did some little trouble but it went fine in Excel.
    However, I wanted to have cell D and E combined as the 4th and last line of the address. With your code, the zip which is column E is set apart as a 5th line. I wanted the state and zip to be combined in a 4th and last row. thank you for your help again.
    Peace..

  6. #6
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Moving Text dynamically to another cell

    Code:
    Option Explicit
    
    Sub ReformatAddresses()
    'Author:    JBeaucaire
    'Date:      1/3/2010
    'Convert row format addresses into columnar format
    Dim LR As Long, i As Long
    Application.ScreenUpdating = False
    LR = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 1 To LR
        Range(Cells(i, "A"), Cells(i, "C")).Copy
        Range("H" & Rows.Count).End(xlUp).Offset(2, 0).PasteSpecial xlPasteAll, , , True
        Range("H" & Rows.Count).End(xlUp).Offset(1, 0) = Cells(i, "D") & "  " & Cells(i, "E")
    Next i
    
    Range("H1:H2").Delete xlShiftUp
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub
    ==========
    If that takes care of your need, be sure to EDIT your original post, click Go Advanced and mark the PREFIX box [SOLVED].


    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated. It is found across from the "time" in each of our posts.)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  7. #7
    Registered User
    Join Date
    01-03-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Moving Text dynamically to another cell

    Man, you are the man..
    That totally solved my problem!
    Thank you and all the best to you!

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0