Excel VBA
Bob Phillips wrote:
Just use Public variables
And for those of us who shun Public variables <g, create a Public
Property for the userform, prevent the userform from unloading itself
(hide it instead) and test the value of the Property e.g.
' ---<Userform1 code module---
Option Explicit
Private m_foundCell As Range
Private Function FindCell()
' Code to find cell goes here e.g.
Set m_foundCell = Range("A1")
End Function
Public Property Get foundCell() As Range
Set foundCell = m_foundCell
End Property
Private Sub UserForm_QueryClose( _
Cancel As Integer, _
CloseMode As Integer)
Me.Hide
Cancel = True
End Sub
' ---</Userform1 code module---
' ---<Calling code ---
Sub test()
Dim rng As Range
Dim thing As UserForm1
Set thing = New UserForm1
With thing
.Show vbModal
Set rng = .foundCell
End With
Set thing = Nothing
' code continues ...
If rng Is Nothing Then
End If
End Sub
Jamie.
--
|