Excel Table to Tabs

balvy

New Member
Joined
Nov 14, 2013
Messages
11
Hello everybody,

I have different tables and workbooks. In Sheet1 of every workbook i have a table that vary in the amount of columns. From this table I have to make a Sheet per column. In each Sheet the cells have to always be column 1 and then the corresponding column. For example:

Table1
ItemsPriceAreaColorDate
shirt2.00upblue12-12-14
pants3.50downred12-11-14

<tbody>
</tbody>

here Sheet2 should be Items and Price, Sheet3 should be Items and Area, Sheet4 should be Items and Color and so on.

Is there anyway i can do this without having to be copying and pasting the columns one by one and be able to do it for different workbooks.

Thanks for all your help.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
One way:

Code:
Sub balvy()
  Dim wks1          As Worksheet
  Dim iCol          As Long
  Dim nCol          As Long

  Set wks1 = Worksheets(1)

  nCol = wks1.Cells(1, Columns.Count).End(xlToLeft).Column
  Do While nCol > Worksheets.Count
    Worksheets.Add After:=Sheets(Sheets.Count)
  Loop

  For iCol = 2 To nCol
    With Worksheets(iCol)
      wks1.Columns(1).Copy .Columns(1)
      wks1.Columns(iCol).Copy .Columns(2)
    End With
  Next iCol
End Sub
 
Upvote 0
Thanks this code is on point. Is there anyway to use the Table headings (Price, Area, Code...) as the names for the different worksheets? If there isn't it's ok you have been more than helpful.
 
Upvote 0
Code:
Sub balvyTwo()
  Dim wks1          As Worksheet
  Dim iCol          As Long
  Dim nCol          As Long

  Set wks1 = Worksheets(1)

  Application.DisplayAlerts = False
  Do While Worksheets.Count > 1
    Worksheets(2).Delete
  Loop
  Application.DisplayAlerts = True
  
  nCol = wks1.Cells(1, Columns.Count).End(xlToLeft).Column
  Do While Worksheets.Count < nCol
    Worksheets.Add After:=Sheets(Sheets.Count)
  Loop

  For iCol = 2 To nCol
    With Worksheets(iCol)
      .Name = wks1.Cells(1, iCol).Value
      wks1.Columns(1).Copy .Columns(1)
      wks1.Columns(iCol).Copy .Columns(2)
    End With
  Next iCol
End Sub

Note that it deletes all but the first sheet at the outset (to avoid a name conflict).
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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