Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-13-2020, 06:29 AM
macropod's Avatar
macropod macropod is offline Adjust Two Columns Without Changing Combined Size Windows 7 64bit Adjust Two Columns Without Changing Combined Size Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default


Did you try the code I posted?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 04-13-2020, 07:56 PM
beno_83au beno_83au is offline Adjust Two Columns Without Changing Combined Size Windows 10 Adjust Two Columns Without Changing Combined Size Office 2019
Novice
Adjust Two Columns Without Changing Combined Size
 
Join Date: Apr 2020
Posts: 5
beno_83au is on a distinguished road
Default

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 View Post
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)?
Reply With Quote
  #3  
Old 04-13-2020, 08:59 PM
BobBridges's Avatar
BobBridges BobBridges is offline Adjust Two Columns Without Changing Combined Size Windows 7 64bit Adjust Two Columns Without Changing Combined Size Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

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
Loop

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
columnCAdjustedWidth = totalWidth - columnBWidth
Columns("c:c").ColumnWidth = columnCAdjustedWidth

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
Nothing wrong with using Columns("B") (or is it "B:B"?) if you want; I'm used to usng numbers, is all.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adjust Two Columns Without Changing Combined Size How to Adjust Every Header Section Size at Once? CrossReach Word 4 03-13-2016 10:49 AM
Adjust Two Columns Without Changing Combined Size 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
Adjust Two Columns Without Changing Combined Size Powerpoint 2013 doesn't adjust size on external display mejnik PowerPoint 1 04-04-2014 09:12 AM
Adjust Two Columns Without Changing Combined Size Adjust Window size at open Gary Drumm Windows 2 03-31-2014 08:22 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:45 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft