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
Any ideas appreciatedVB:Application.Goto Target Selection.ColumnWidth = intLargestString
Auto Merged Post;
Solved - the worksheet was protected
Last edited by cymro; August 22nd, 2007 at 06:39. Reason: Auto Merged Doublepost
"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 insertingimmediately before the problem line to see what it returns?VB:MsgBox Target.address
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.
Please help Oz share knowledge among all users by posting your questions in a public forum rather than using a Private Message.
There are currently 1 users browsing this thread. (0 members and 1 guests)