0

This question is in accordance to the following question:

Visual Basic move all other columns to create one long column B

I used the best answer:

sub ss()
    Dim col As Range

    For Each col In Worksheets("Sheet1").Columns
        If (col.Column > 1 And col.Column < 171) Then
            Range(col.Rows(1), col.Rows(15)).Select
            Selection.Cut
            'Select cell at bottom of A
            ActiveSheet.Range("a1").End(xlDown).Offset(1, 0).Select
            ActiveSheet.Paste   'Paste
        End If
    Next col
End Sub

Now this works, but it tiles all of the columns in the excel sheet to one single column. What I want to do is do it only for the selected columns when running the macro not for the whole sheet.

Is that possible? How?

Community
  • 1
  • 1
salomari87
  • 26
  • 3

1 Answers1

0

Like this?

Sub Sample()
    Dim col As Range
    For Each col In Selection.Columns
        If col.Column > 1 And col.Column < 171 Then
            Range(col.Rows(1), col.Rows(15)).Select
            Selection.Cut
            ActiveSheet.Range("a1").End(xlDown).Offset(1, 0).Select
            ActiveSheet.Paste
        End If
    Next col
End Sub
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250