![]() |
|
|
|
#1
|
||||
|
||||
|
Did you try the code I posted?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#2
|
|||
|
|||
|
Thanks Bob and Avri, I wasn't aware of that as a debugging method, although I'm no longer getting error messages now.
And yes, I did try the code, and it works to set both columns when I enter a width for Column B. So I have been trying to re-write that into a loop to resize C when I drag to resize B (p.s. Sorry if I'm not picking up on what you're telling me). I wen't on a bit of an adventure last night with it, and now with a fresh head I think I made have done things a little better...... So here's what I've got and then where I'm stuck: Code:
Sub CommandButton1_Click()
Dim totalWidth As Single, columnBWidth As Single, columnCAdjustedWidth As Single
totalWidth = Columns("b").ColumnWidth + Columns("c").ColumnWidth
Do While Selection.Columns.Count = 2
columnBWidth = Columns("b").ColumnWidth
columnCAdjustedWidth = totalWidth - columnBWidth
Columns("c:c").ColumnWidth = columnCAdjustedWidth
Application.Wait(Now + TimeValue("0:00:01"))
MsgBox ("Column adjusted")
Loop
MsgBox ("Ended.")
End Sub
|
|
#3
|
||||
|
||||
|
I see something in your program that makes me afraid to try it for myself, but I think I can describe it and you tell me whether I'm mistaken.
1) First step makes sense; you're getting the width of the two columns: totalWidth = Columns("b").ColumnWidth + Columns("c").ColumnWidth 2) I don't understand this part: You start a loop, and tell it to go on doing it over and over as long as your selection takes in cells in exactly two columns. But I don't see that anything inside the loop changes that selection, so the program will go on running, redoing the loop again and again. Do While Selection.Columns.Count = 2 3) What you do inside the loop looks like it started out to make sense: You want to adjust the width of column C to make B+C come out to the desired width. Looks to me, though, as if you made it actually come out to the same width it already was. That's because you're using the actual width instead of the desired width: columnBWidth = Columns("b").ColumnWidth 4) I also don't get what the Wait statement is for, but I don't think it's hurting anything. Excel seems to freeze, as I see it, because it's running the loop over and over again. Here's what I would do: Code:
Sub CommandButton1_Click() Columns(3).ColumnWidth = 539 - Columns(2).ColumnWidth End Sub |
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
How to Adjust Every Header Section Size at Once?
|
CrossReach | Word | 4 | 03-13-2016 10:49 AM |
How do I adjust the size of the printed slide
|
Suppy | PowerPoint | 2 | 01-27-2015 02:15 AM |
| How to adjust Image size and other question | arjfca | Word VBA | 1 | 12-05-2014 02:00 AM |
Powerpoint 2013 doesn't adjust size on external display
|
mejnik | PowerPoint | 1 | 04-04-2014 09:12 AM |
Adjust Window size at open
|
Gary Drumm | Windows | 2 | 03-31-2014 08:22 AM |