+ Reply to Thread
Results 1 to 10 of 10

Macro to move data horizontal in one line

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-08-2017
    Location
    London
    MS-Off Ver
    Office 2007
    Posts
    122

    Macro to move data horizontal in one line

    I have data in column B that run down I want to the data to look like column C. You will notice column B the value run down....I need it to look like the data in Column C

    Rep given for someone that can assist with a macro to do the whole column B's data to column C.also in Column C if the spaces can be deleted as it should look like


    145
    125
    149 ......no spaces in column C

    Thanks for any help
    Attached Images Attached Images

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,049

    Re: Macro to move data horizontal in one line

    Try:
    Sub JohnGreen()
        Application.ScreenUpdating = False
        Dim LastRow As Long, x As Long
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        For x = 1 To LastRow Step 4
            Cells(x, 3) = Join(Application.Transpose(Range(Cells(x, 2), Cells(x + 2, 2)).Value), "")
        Next x
        Columns(3).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    11-08-2017
    Location
    London
    MS-Off Ver
    Office 2007
    Posts
    122

    Re: Macro to move data horizontal in one line

    Quote Originally Posted by Mumps1 View Post
    Try:
    Sub JohnGreen()
        Application.ScreenUpdating = False
        Dim LastRow As Long, x As Long
        LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        For x = 1 To LastRow Step 4
            Cells(x, 3) = Join(Application.Transpose(Range(Cells(x, 2), Cells(x + 2, 2)).Value), "")
        Next x
        Columns(3).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
        Application.ScreenUpdating = True
    End Sub
    Hi thanks very much for your help but this splited one number off ??

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Macro to move data horizontal in one line

    Another option
    Sub JohnGreen2()
       Dim Rng As Range
       
       For Each Rng In Range("B:B").SpecialCells(xlConstants).Areas
          Rng.Offset(, 1).Resize(1, 1).Value = join(Application.Transpose(Rng), "")
       Next Rng
    End Sub

  5. #5
    Forum Contributor
    Join Date
    11-08-2017
    Location
    London
    MS-Off Ver
    Office 2007
    Posts
    122

    Re: Macro to move data horizontal in one line

    Quote Originally Posted by Fluff13 View Post
    Another option
    Sub JohnGreen2()
       Dim Rng As Range
       
       For Each Rng In Range("B:B").SpecialCells(xlConstants).Areas
          Rng.Offset(, 1).Resize(1, 1).Value = join(Application.Transpose(Rng), "")
       Next Rng
    End Sub
    Fluff13 thank you very much this works great but your macro dont delete spaces in column C....but it works great.....just need spaces removed in Column C then its perfect. Thanks very much

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,049

    Re: Macro to move data horizontal in one line

    The macro assumes that there is only one blank row between groups of numbers. Fluff's macro will take care of that. Just add
    Columns(3).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    to his code to delete the spaces.

  7. #7
    Forum Contributor
    Join Date
    11-08-2017
    Location
    London
    MS-Off Ver
    Office 2007
    Posts
    122

    Re: Macro to move data horizontal in one line

    Quote Originally Posted by Mumps1 View Post
    The macro assumes that there is only one blank row between groups of numbers. Fluff's macro will take care of that. Just add
    Columns(3).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    to his code to delete the spaces.
    Thank you very much rep for both off you for your help
    Last edited by JohnGreen2; 03-09-2019 at 01:12 PM.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,049

    Re: Macro to move data horizontal in one line

    Glad we could help.

  9. #9
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,789

    Re: Macro to move data horizontal in one line

    You're welcome & thanks for the feedback

  10. #10
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,700

    Re: Macro to move data horizontal in one line

    No need to worry about empty cells in the results column.
    Sub Maybe()
    Dim myAreas As Areas, i As Long
    Set myAreas = Sheets("Sheet1").Columns(2).SpecialCells(2).Areas
        For i = 1 To myAreas.Count
            Cells(i, 3).Value = Join(Application.Transpose(myAreas(i)), "")
        Next i
    End Sub
    Last edited by jolivanes; 03-10-2019 at 03:40 AM. Reason: code tags

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] MOVE PAGE BREAK IN HORIZONTAL border LINE EXCEL VBA
    By rajeshn_in in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2019, 12:05 PM
  2. Replies: 2
    Last Post: 07-04-2018, 06:00 AM
  3. [SOLVED] Horizontal line at the end of data list
    By John19 in forum Excel General
    Replies: 2
    Last Post: 07-12-2015, 06:25 AM
  4. [SOLVED] How to create macro to move multiple horizontal data to vertical
    By Pony08 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-15-2013, 10:07 AM
  5. Macro to move horizontal data to vertical - in new sheet--excluding blank cells
    By Jackdaddy0711 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-25-2012, 12:54 PM
  6. move data from vertial to horizontal
    By Jamie714 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2009, 03:01 AM
  7. Move data from horizontal to vertical
    By JustMe602 in forum Excel General
    Replies: 9
    Last Post: 11-28-2006, 04:14 PM

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