Advertisement
Guest User

Untitled

a guest
May 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. Sub ColumnsToOne()
  2.  
  3. Dim i As Integer
  4. Dim Lastrow As Long
  5. Dim Lastrowb As Long
  6.  
  7. LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
  8. Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1
  9.  
  10. For i = 2 To LastColumn
  11. Lastrowb = Cells(Rows.Count, i).End(xlUp).Row
  12. Range(Cells(1, i), Cells(Lastrowb, i)).Copy Destination:=Cells(Lastrow, 1)
  13. Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1
  14. Next
  15.  
  16. End Sub
  17.  
  18. Sub CombineColumns1()
  19.  
  20. Dim xRng As Range
  21. Dim i As Integer
  22. Dim xLastRow As Integer
  23. Dim xTxt As String
  24. On Error Resume Next
  25.  
  26. xTxt = Application.ActiveWindow.RangeSelection.Address
  27.  
  28. Set xRng = Application.InputBox("please select the data range", "ColumnToOne", xTxt, , , , , 8)
  29.  
  30. If xRng Is Nothing Then Exit Sub
  31. xLastRow = xRng.Columns(1).Rows.Count + 1
  32.  
  33. For i = 2 To xRng.Columns.Count
  34. Range(xRng.Cells(1, i), xRng.Cells(xRng.Columns(i).Rows.Count, i)).Cut
  35. ActiveSheet.Paste Destination:=xRng.Cells(xLastRow, 1)
  36. xLastRow = xLastRow + xRng.Columns(i).Rows.Count
  37. Next
  38. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement