Convert data From Vertical to Horizontal Format

reyrey

New Member
Joined
Jun 30, 2011
Messages
49
How do you create macro to have move multiple numeric data from a vertical format to horizontal format using the plus (+) sign to separate each numeric data that does not have minus (-) sign. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>Problem is: <o:p></o:p>
<o:p> </o:p>-1
-2<o:p></o:p>
-3<o:p></o:p>
0<o:p></o:p>
2<o:p></o:p>
<o:p> </o:p>
Results required will be: <o:p></o:p>
<o:p> </o:p>-1-2-3+0+2<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>Any advice or help will be greatly appreciated...Thank you<o:p></o:p>
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Maybe something like this:
Code:
Sub a_test()
Range(Range("A2"), Range("A2").End(xlDown)).NumberFormat = "+#;-#;+0"

Range(Range("A2"), Range("A2").End(xlDown)).Copy
Range("B2").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
        
Application.CutCopyMode = False
End Sub
 
Upvote 0
Hi, this will work by just highlighting all the cells that you want to change to horizontal from vertical and activating the macro, no need to worry about what cells the entries are in.

Code:
Sub VertHor()
    Dim i As Integer
    Dim N As Integer
    N = Application.WorksheetFunction.count(Selection)
    For i = 1 To N
        ActiveCell.Offset(i, 0).Select
        Selection.Cut
        ActiveCell.Offset(-i, i).Select
        ActiveSheet.Paste
        ActiveCell.Offset(0, -i).Select
    Next i
End Sub

Hmm I think maybe I misread, you want the answer to all come out in a single cell? Well, I guess ill leave this here anyway but the post above is probably what you need.
 
Last edited:
Upvote 0
Thanks for the reply!

Both codes work great but how would you get the outcome to a single cell instead of multiple cells?
 
Upvote 0
With headline in A1 and data from A2 and down
Code:
Sub a_2_test()

fr1 = Cells(Rows.Count, 1).End(xlUp).Row
Range(Range("A2"), Range("A2").End(xlDown)).NumberFormat = "+#;-#;+0"

For i = 2 To fr1
    con = con & Range("a" & i).Text
Next
Range("B2") = con

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top