+ Reply to Thread
Results 1 to 2 of 2

Split up existing worksheet into worksheets via macros

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-28-2010
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    105

    Split up existing worksheet into worksheets via macros

    Hi I have attached a sample workbook.
    I would like to create a Macros which can take the existing worksheet and split it up into worksheets for each merged cell entry in column A. Basically you can see that the first entry, runs from row 1 to row 44, I would like to cut all those and paste that to a new worksheet and name it after the entry which in this case is "land erfeim", and do this for all subsequent merged cells.. reason being is i have more data in the subsequent columns for each unique row.
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Split up existing worksheet into worksheets via macros

    It's best to avoid merged cells
    
    Option Explicit
    
    Public Sub SplitMerged()
        Dim oWs As Excel.Worksheet
        Dim rCL As Excel.Range
        Dim uRng As Excel.Range
        Dim MyAddr As String
        Dim r As Long
        Dim c As Long
        Dim LastRow As Long
        Dim LastColumn As Long
        On Error Resume Next
    
        Application.ScreenUpdating = False
    
        Set oWs = ActiveSheet
    
        Set uRng = oWs.UsedRange
        LastRow = uRng.Rows(uRng.Rows.Count).Row
        LastColumn = uRng.Columns(uRng.Columns.Count).Column
    
        ' Find the merged cells
        For r = 1 To LastRow
            For c = 1 To LastColumn
                Cells(r, c).Select
                MyAddr = Selection.Address
                If Len(WorksheetFunction.Substitute(MyAddr, ":", "")) <> Len(MyAddr) Then
                    With Range(MyAddr)
                        Worksheets.Add after:=Worksheets(Worksheets.Count)
                        .Copy ActiveSheet.Cells(1, 1)
                    End With
                End If
                
            Next c
        Next r
        oWs.Select
        Set uRng = Nothing
    
        On Error GoTo 0
        Application.ScreenUpdating = True
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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