Results 1 to 5 of 5

Get data from split/merged cells

Threaded View

  1. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Trying to get data from split/merged cells but not having any luck...

    Hello garymrowe,

    Welcome to the Forum!

    The macro below will remove the merged cells on the "Source" worksheet. This has been added to the attached workbook.
    'Written: February 02, 2011
    'Author:  Leith Ross
    'Summary: Removes all merged cells in a table and fills the unmerged cells with merged
    '         cell value.
    
    Sub RemoveMergedCells()
    
      Dim C As Long
      Dim Data As Variant
      Dim LastCol As Long
      Dim LastRow As Long
      Dim MergeRng As Range
      Dim R As Long
      Dim Rng As Range
      Dim Wks As Worksheet
      
        Set Wks = Worksheets("Source")
        Set Rng = Wks.Range("A1").CurrentRegion
        Set Rng = Rng.Offset(1, 0).Resize(RowSize:=Rng.Rows.Count - 1)
        
          LastCol = Rng.Columns.Count + Rng.Column - 1
          LastRow = Rng.Rows.Count
          
          Application.ScreenUpdating = False
          
          For C = 1 To LastCol
            For R = Rng.Row To LastRow
              Set MergeRng = Wks.Cells(R, C).MergeArea
              If MergeRng.Address <> Wks.Cells(R, C).Address Then
                 R = R + MergeRng.Rows.Count - 1
                 Data = MergeRng.Cells(1, 1).Value
                 MergeRng.UnMerge
                 MergeRng.FillDown
              End If
            Next R
          Next C
          
          Application.ScreenUpdating = True
          
    End Sub

    To Run the Macro...
    To run the macro from Excel, open the workbook, and press ALT+F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

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