View Single Post
 
Old 04-13-2020, 09:22 PM
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

Hey Bob. First up, the wait was just an experiment to see if reducing the number of cycles would stop the freezing, but it didn't help. As you said, I don't think it hurt either.

For the loop, I was under the understanding that the condition would be analysed each cycle, so that when I de-selected the 2 columns it'd return false. But I've been informed that this is not the case and that I'd need to set a variable and check it inside the loop.

For the widths, the numbers checked out IIRC. So, subtract B width from the desired total width to give C's width, then set C.

And I liked using B/C to refer to the columns themselves when I was not using a Selection. Otherwise, I'd use numbers for the index positions.

HOWEVER, after talking to a mate over Discord, he did me up some code for a SelectionChange event that works nicely. The only requirement is that after resizing I just need to select a cell to force the change. So that works well enough for now:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim tWidths As Double
    tWidths = 75.57
    If Not Columns("B").ColumnWidth + Columns("C").ColumnWidth = tWidths Then
        Columns("C").ColumnWidth = tWidths - Columns("B").ColumnWidth
    End If
End Sub
I think this seems to be the best that can be done for what I was trying to do, as there's no event that covers resizing (as far as he knows anyway).
Reply With Quote