+ Reply to Thread
Results 1 to 3 of 3

create new sheets from a header row

  1. #1
    Craig
    Guest

    create new sheets from a header row

    I'm trying to take a sheet of compiled data and create several sheets
    of individual data. The headers are in column A, so i'm trying to
    create a new sheet in the workbood for each value of column A. It
    keeps bombing out at different points, depending on what i try, here's
    what i have so far, the values in colum A start at A6, it's flagging
    For Each C In MyRange right now, any ideas?

    Sub NewSheet()
    Dim MyRange As Range
    Dim C As Range
    Dim NewSheetName As String
    Range("A6").Select
    ActiveCell.End(xlDown).Select
    xLastRow = ActiveCell.Row
    Range("A6" & xLastRow).Name = "MyRange"

    For Each C In MyRange
    Range("A" & MyRange).Name = "C"
    C.Select
    NewSheetName = Selection.Value
    Sheets.Add Type:="Worksheet"
    With ActiveSheet
    .Move After:=Worksheets(Worksheets.Count)
    .Name = NewSheetName
    End With
    Next C

    End Sub


  2. #2
    Rowan Drummond
    Guest

    Re: create new sheets from a header row

    Try:

    Sub newSheet()
    Dim MyRange As Range
    Dim C As Range
    Dim NewSheetName As String
    Dim newSheet As Worksheet
    Dim xLastRow As Long

    xLastRow = Cells(Rows.Count, "A").End(xlUp).Row
    Set MyRange = Range("A6:A" & xLastRow)

    For Each C In MyRange
    NewSheetName = C.Value
    Set newSheet = Sheets.Add
    With newSheet
    .Move After:=Worksheets(Worksheets.Count)
    On Error Resume Next
    .Name = NewSheetName
    On Error GoTo 0
    End With
    Next C

    End Sub

    Hope this helps
    Rowan

    Craig wrote:
    > I'm trying to take a sheet of compiled data and create several sheets
    > of individual data. The headers are in column A, so i'm trying to
    > create a new sheet in the workbood for each value of column A. It
    > keeps bombing out at different points, depending on what i try, here's
    > what i have so far, the values in colum A start at A6, it's flagging
    > For Each C In MyRange right now, any ideas?
    >
    > Sub NewSheet()
    > Dim MyRange As Range
    > Dim C As Range
    > Dim NewSheetName As String
    > Range("A6").Select
    > ActiveCell.End(xlDown).Select
    > xLastRow = ActiveCell.Row
    > Range("A6" & xLastRow).Name = "MyRange"
    >
    > For Each C In MyRange
    > Range("A" & MyRange).Name = "C"
    > C.Select
    > NewSheetName = Selection.Value
    > Sheets.Add Type:="Worksheet"
    > With ActiveSheet
    > .Move After:=Worksheets(Worksheets.Count)
    > .Name = NewSheetName
    > End With
    > Next C
    >
    > End Sub
    >


  3. #3
    Craig
    Guest

    Re: create new sheets from a header row

    that worked perfectly, thanks a lot


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1