Macro to create new worksheet for each column, keeping first 2 columns in each new worksheet

sharicn

New Member
Joined
May 24, 2010
Messages
32
Hello!

I have a worksheet with about 32 columns that I download periodically as people buy raffle tickets for an event we're putting on. In order to upload the raffle tickets to our random raffle picker application, I need to divide the bigger worksheet into individual worksheets - one sheet for each raffle item. I played with some code on my own, then did a search here and found this, which gets me partway there:

VBA Code:
Sub copycols()
Dim LC As Long, i As Long, ws As Worksheet
With ActiveSheet
    LC = .Cells(1, Columns.Count).End(xlToLeft).Column
    For i = 2 To LC
        Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
        .Columns(1).Copy Destination:=ws.Range("A1")
        .Columns(i).Copy Destination:=ws.Range("B1")
        ws.Name = Range("B1").Value
    Next i
End With
End Sub

My only issue, that I can't quite figure out on my own, is that I need both column A AND column B to copy to each new worksheet, and the worksheets to be named from the value in cell C1 (well, that part is easy, lol). Each time I think I have it logically figured out, I get an error. I'm sure it's something obvious I'm missing, but my VBA skills are a little rusty.

Any help would be greatly appreciated.

Thanks,
Shari
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,215,647
Messages
6,126,005
Members
449,279
Latest member
Faraz5023

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