Consulting

Results 1 to 3 of 3

Thread: Unmerge VBA with dates

  1. #1
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    2
    Location

    Unmerge VBA with dates

    Hi All,

    I got VBA code of this forum to unmerge and copy cells across. It was working perfectly until it came to the dates in a column. As it was using autocomplete I'm getting incremental values across the 5 column headings it unmerge. Can someone please help me with the code so it doesn't autofill incremental values as headings across the unmerged cells?

    Thank you

    Public Sub ProcessData()
    Dim cell As Range
    Dim MergedCell As Range
    Dim NumRows As Long
    Dim NumCols As Long
    
        With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
        End With
        With ActiveSheet
            For Each cell In Range("A1").Resize( _
                .Cells.SpecialCells(xlCellTypeLastCell).Row, _
                .Cells.SpecialCells(xlCellTypeLastCell).Column)
                If cell.MergeCells Then
                    NumRows = cell.MergeArea.Rows.Count
                    NumCols = cell.MergeArea.Columns.Count
                    cell.UnMerge
                    If NumRows > 1 Then cell.AutoFill cell.Resize(NumRows)
                    If NumCols > 1 Then cell.Resize(NumRows).AutoFill cell.Resize(NumRows, NumCols)
                End If
            Next cell
        End With
        With Application
            .Calculation = xlCalculationAutomatic
            .ScreenUpdating = True
        End With
    End Sub
    Last edited by Bob Phillips; 04-10-2019 at 02:18 AM. Reason: Added code tags

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    Public Sub ProcessData()
    Dim cell As Range
    Dim MergedCell As Range
    Dim NumRows As Long
    Dim NumCols As Long
    
        With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
        End With
        With ActiveSheet
            For Each cell In Range("A1").Resize( _
                .Cells.SpecialCells(xlCellTypeLastCell).Row, _
                .Cells.SpecialCells(xlCellTypeLastCell).Column)
                If cell.MergeCells Then
                    NumRows = cell.MergeArea.Rows.Count
                    NumCols = cell.MergeArea.Columns.Count
                    cell.UnMerge
                    If NumRows > 1 Then cell.AutoFill cell.Resize(NumRows), xlFillCopy
                    If NumCols > 1 Then cell.Resize(NumRows).AutoFill cell.Resize(NumRows, NumCols), xlFillCopy
                End If
            Next cell
        End With
        With Application
            .Calculation = xlCalculationAutomatic
            .ScreenUpdating = True
        End With
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    2
    Location
    Works brilliantly! Much appreciated, 😊

    Quote Originally Posted by xld View Post
    Try this

    Public Sub ProcessData()
    Dim cell As Range
    Dim MergedCell As Range
    Dim NumRows As Long
    Dim NumCols As Long
    
        With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
        End With
        With ActiveSheet
            For Each cell In Range("A1").Resize( _
                .Cells.SpecialCells(xlCellTypeLastCell).Row, _
                .Cells.SpecialCells(xlCellTypeLastCell).Column)
                If cell.MergeCells Then
                    NumRows = cell.MergeArea.Rows.Count
                    NumCols = cell.MergeArea.Columns.Count
                    cell.UnMerge
                    If NumRows > 1 Then cell.AutoFill cell.Resize(NumRows), xlFillCopy
                    If NumCols > 1 Then cell.Resize(NumRows).AutoFill cell.Resize(NumRows, NumCols), xlFillCopy
                End If
            Next cell
        End With
        With Application
            .Calculation = xlCalculationAutomatic
            .ScreenUpdating = True
        End With
    End Sub

Tags for this Thread

Posting Permissions

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