Ozgrid Excel Help & Best Practices Forums

Excel Training / Excel Dashboards Reports

Results 1 to 2 of 2

Thread: Unable to Set the ColumnWidth Property of the Range Class. Merged Cell

  1. #1
    Join Date
    2nd June 2007

    Unable to Set the ColumnWidth Property of the Range Class. Merged Cell

    When a user selects a merged cell within a named range the column width is reset to accommodate the longest string in a separate list. In order to do this the code first loops through the list to get the largest string which it places in a variable intLargestString. The code fails on the second line below with run-time error '1004' unable to set the ColumnWidth property of the Range class

    Application.Goto Target
    Selection.ColumnWidth = intLargestString
    Any ideas appreciated
    Auto Merged Post;

    Solved - the worksheet was protected
    Last edited by cymro; August 22nd, 2007 at 07:39. Reason: Auto Merged Doublepost

    Excel Video Tutorials / Excel Dashboards Reports

  2. #2
    Join Date
    22nd April 2003
    Virginia, USA

    Re: Set Column Width Of Merged Cell

    "Target" suggest that you are using an event macro. If your code is changing the active cell, then the event macro may be firing multiple times -- with a different "Target." Have you tried inserting
    MsgBox Target.address
    immediately before the problem line to see what it returns?

    But as an aside, I would offer that it is good practice to avoid using merged cells. THey can cause havoc with VBA code. Use Format > Center Across Selection or other formatting tricks to accomplish teh look of a merged cell without actually using one.
    Best Regards,
    Please help Oz share knowledge among all users by posting your questions in a public forum rather than using a Private Message.

Thread Information

Users Browsing this Thread

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

Possible Answers

  1. Replies: 4
    Last Post: December 2nd, 2014, 04:48
  2. Replies: 3
    Last Post: October 15th, 2011, 04:38
  3. Replies: 2
    Last Post: January 11th, 2007, 18:10
  4. Replies: 9
    Last Post: October 31st, 2006, 20:09
  5. Replies: 4
    Last Post: September 19th, 2006, 06:05


Posting Permissions

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