Technology
New Member
- Joined
- Apr 29, 2021
- Messages
- 25
- Office Version
- 365
- Platform
- Windows
How do you take a set of values (rows and columns) in EXCEL and use VBA to puts all those values into one row?
Sub CopySingleDataRowAndSortIt()
Dim Data As Range
Set Data = Range("A1", Cells(1, Columns.Count).End(xlToLeft))
Data.Copy Data(1).Offset(1)
With Data.Parent.Sort
.SortFields.Clear
.SortFields.Add2 Key:=Data.Offset(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
.SetRange Data.Offset(1)
.Orientation = xlLeftToRight
.Apply
End With
End Sub
Give this macro a try...
VBA Code:Sub CopySingleDataRowAndSortIt() Dim Data As Range Set Data = Range("A1", Cells(1, Columns.Count).End(xlToLeft)) Data.Copy Data(1).Offset(1) With Data.Parent.Sort .SortFields.Clear .SortFields.Add2 Key:=Data.Offset(1), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal .SetRange Data.Offset(1) .Orientation = xlLeftToRight .Apply End With End Sub
Tip: you need to know how many numbers/cells there are (this you know).finding the median of the order row
@Technology - I can see that @Rick Rothstein's code helped you in this question.Yes, this works. Thank you!