moving columns to new sheet excel VBA

addimatty

New Member
Joined
Mar 16, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
So I have a sheet with information in columns (approx 200) which I would like to move to new sheet. The idea is that I need column A in each new sheet following with column B, then next sheet again column A + column C and so on till the last column. Could someone help me with this?

Columns("A:B").Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
Sheets("Sheet1").Select
Columns("C:C").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet4").Select
Columns("C:C").Select
ActiveSheet.Paste
Sheets.Add After:=ActiveSheet
Sheets("Sheet1").Select
Range("A:B,D:D").Select
Range("D1").Activate
Application.CutCopyMode = False
Selection.Copy
Sheets("Sheet5").Select
ActiveSheet.Paste
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Welcome to the forum.
Try this in a standard module:
VBA Code:
Sub OutputColumnValuesToNewSheets()
    Dim i As Long, lc As Long, lr As Long, ws1 As Worksheet, newWs As Worksheet
    
    Set ws1 = Sheets("Sheet1")
    lc = ws1.Cells(1, Columns.Count).End(xlToLeft).Column
    lr = ws1.Cells(Rows.Count, 1).End(xlUp).Row
    
    Application.ScreenUpdating = False
    For i = 2 To lc
        Set newWs = Worksheets.Add(, Sheets(Sheets.Count))
        With newWs
            .Name = "Column " & Split(ws1.Cells(1, i).Address, "$")(1)
            ws1.Range("A1").Resize(lr).Copy .Range("A1")
            ws1.Cells(1, i).Resize(lr).Copy .Range("B1")
        End With
    Next i
    ws1.Activate
    Application.ScreenUpdating = True
    MsgBox "Exported data for " & lc & " columns", vbInformation, "Exported Data Successfully"
End Sub
 
Upvote 0
Also, I used the following code when I needed to delete all sheets except for Sheet1.
Maybe this will be useful for you sometimes.
Note: Don't run it unless you need to delete worksheets!
VBA Code:
Sub DeleteSheetsExceptForSheet1()
    Dim msg As Long
    msg = MsgBox("Are you sure you want to delete all the sheets except for Sheet1?", vbYesNo, "Confirmation")
    If msg = vbYes Then
        For Each Sheet In Sheets
            Application.DisplayAlerts = False
            If Sheet.Name <> "Sheet1" Then Sheet.Delete
            Application.DisplayAlerts = True
        Next Sheet
    Else
        MsgBox "Cancelled", vbInformation
    End If
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
Another option
VBA Code:
Sub addimatty()
   Dim Ary As Variant, Rws As Variant
   Dim i As Long
   
   Application.ScreenUpdating = False
   With Sheets("Sheet1")
      i = .Cells(1, Columns.Count).End(xlToLeft).Column
      Ary = .Range("A1", .Range("A" & Rows.Count).End(xlUp)).Resize(, i)
   End With
   Rws = Evaluate("row(1:" & UBound(Ary) & ")")
   For i = 2 To UBound(Ary, 2)
      With Sheets.Add(, Sheets(i - 1))
         .Range("A1").Resize(UBound(Ary), 2).Value = Application.Index(Ary, Rws, Array(1, i))
      End With
   Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,872
Messages
6,181,500
Members
453,047
Latest member
charlie_odd

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