View Single Post
 
Old 04-13-2020, 06:21 AM
beno_83au beno_83au is offline Windows 10 Office 2019
Novice
 
Join Date: Apr 2020
Posts: 5
beno_83au is on a distinguished road
Default

Ok, so thanks for the help guys. Having never worked with Excel VBS you got me started in the right direction. Now that I've come up with some code to work with, it's giving me some errors that I have not been able to correct:

Code:
Sub CommandButton1_Click()
Dim columnBWidth As Single, columnCWidth As Single, totalWidth As Single
columnBWidth = Columns("b").ColumnWidth
columnCWidth = Columns("c").ColumnWidth
totalWidth = columnBWidth + columnCWidth
Do While Selection.Columns.Count = 2
With Selection
    Dim columnBNewWidth As Single, columnCAdjustedWidth As Single
    columnBNewWidth = Selection(1).ColumnWidth
    columnCAdjustedWidth = totalWidth - columnBNewWidth
    Worksheets("Sheet1").Range("c:c").ColumnWidth = columnCAdjustedWidth
End With
Loop
MsgBox ("Ended.")
End Sub
So, as stated in the OP, when dragging to resize Column B I'm trying to auto-resize Column C to maintain the original width of B + C. Using some MsgBox'es along the way to test the returns seems good. But when I try to resize C, Excel crashes.

I tried wrapping Worksheets("Sheet1").Range(Columns("c:c")).ColumnW idth = columnCAdjustedWidth with Sub Column_Width() but after looking up that error I learnt that you can't overlap subroutines.

I'm not ashamed to say I've spent all evening on this My experience with writing code is as a self-taught ArmA coder, so I'm used to putting in unreasonable amounts of time to make something work on my own. But now I'm stuck. How do I get this to work?

Last edited by beno_83au; 04-13-2020 at 06:25 AM. Reason: Found an error, changed it, new problem :)
Reply With Quote