Results 1 to 8 of 8

Merged Cells and Column Width

Threaded View

schmidt1962 Merged Cells and Column Width 11-24-2013, 02:01 PM
Jim28 Re: Merged Cells and Column... 11-24-2013, 02:33 PM
AlphaFrog Re: Merged Cells and Column... 11-24-2013, 02:34 PM
schmidt1962 Re: Merged Cells and Column... 11-24-2013, 02:43 PM
mehmetcik Re: Merged Cells and Column... 11-24-2013, 04:05 PM
schmidt1962 Re: Merged Cells and Column... 11-24-2013, 08:07 PM
AlphaFrog Re: Merged Cells and Column... 11-24-2013, 08:24 PM
schmidt1962 Re: Merged Cells and Column... 11-24-2013, 09:19 PM
  1. #5
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Merged Cells and Column Width

    Hi

    I created a workbook

    C2 and D2 are merged

    D3 downwards and c3 downwards are data.

    This code snippet sets the width of columns C ad D using the cells from C3 and D3 downwards.

    However if the text is larger than the sum of C3 and D3 then those columns are made wider to match C/D 3.

    
    Sub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        Range("E3:F17").Select
        Selection.Columns.AutoFit
        EWidth = Range("E3").ColumnWidth
        FWidth = Range("F3").ColumnWidth
    
        Range("E2:F2").Select
        Selection.UnMerge
        Range("E2").Columns.AutoFit
    
        MWidth = Range("E2").ColumnWidth
        Range("E2:F2").Select
         With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Selection.Merge
        
        If MWidth > EWidth + FWidth Then
        Range("E3").ColumnWidth = EWidth * MWidth / (EWidth + FWidth)
        Range("F3").ColumnWidth = FWidth * MWidth / (EWidth + FWidth)
        End If
        
        EWidth = Range("E3").ColumnWidth
        FWidth = Range("F3").ColumnWidth
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] column width macro in merged cell seems to have problem
    By anand_erin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-30-2012, 08:29 AM
  2. Replies: 8
    Last Post: 08-06-2009, 09:02 AM
  3. [SOLVED] copy a column of single cells into a column of merged cells
    By clairejane_99@hotmail.com in forum Excel General
    Replies: 3
    Last Post: 08-17-2006, 09:30 AM
  4. width of Merged cells within un merged cells
    By Darin Kramer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2005, 06:05 AM
  5. Merged cells width
    By davegb in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-01-2005, 05:05 PM

Tags for this Thread

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