Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / 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
    Posts
    33

    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

    VB:
    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 06:39. Reason: Auto Merged Doublepost

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    22nd April 2003
    Location
    Virginia, USA
    Posts
    5,035

    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
    VB:
    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,
    Tom
    ---------------------------
    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: 3
    Last Post: October 15th, 2011, 03:38
  2. Replies: 3
    Last Post: September 20th, 2007, 05:44
  3. Replies: 2
    Last Post: January 11th, 2007, 17:10
  4. Replies: 9
    Last Post: October 31st, 2006, 19:09
  5. Replies: 4
    Last Post: September 19th, 2006, 05:05

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
  •  
porno