Thanks Bob and Avri, I wasn't aware of that as a debugging method, although I'm no longer getting error messages now.
Quote:
Originally Posted by macropod
Did you try the code I posted?
|
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
When I run this, Excel seems to freeze until the "Column adjusted" message box appears (~1 second). The problem I'm having now is that with Excel frozen, I can't drag to resize anything obviously, and removing the MsgBox command just means I've got to force close to try again. Is it possible to run the loop in the background while I'm working on the sheet? Or should I be using one of the events that I've since discovered instead (that I had even less success with last night)?