Forum Discussion

Riley_Johnson's avatar
Riley_Johnson
Copper Contributor
May 05, 2024

Why does my Userform freeze when ShowModal is False?

I am new to Modal and Modeless Userforms. I am trying to build a simple Userform as a proof of concept that you can change the contents of cells on a sheet and still run your Userform. My goal is to have a Userform that stays loaded, shown, and swaps the values of two cells every time I hit swap cells.

 

For simplicity's sake, let's just assume that no data validation is needed. 

 

This Userform has two RefEdits and a Command Button called cmdSwapCells. When hit, the command button swaps the contents of the two cells referenced by the RefEdits.  Here is the code for the sub, SwapCellValues, which is called when the cmdSwapCells_Enter or the cmdSwapCells_Click events trigger.

 

Update:

 

The code seems to work if I use TextBoxes instead of RefEdits. Are RefEdits and vbModeless a known source of bugs?

 

Sub SwapCellValues(refOne As String, refTwo As String)

    Dim RangeA As Range, RangeB As Range
    Dim ValA As String, ValB As String
    
    Set RangeA = Range(refOne)
    Set RangeB = Range(refTwo)
    
    ValA = RangeA.Value
    ValB = RangeB.Value
    
    RangeA.Value = ValB
    RangeB.Value = ValA
       
End Sub

 

 

 

 

 

 

1 Reply

Resources