Setting Userform textbox value from Worksheet_Change

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
609
Hi,

The following works fine (I'm currently using Userform1 with vbModeless)

Userform1.Textbox1.Value = Target

I just want to know what affect this has when the Userform hasn't been loaded.
It seems nothing happens but is it using memory? Or a bad idea?

Can I check whether the Userform is open

Any help appreciated
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
4,254
You could use a Public Boolean variable that is TRUE when form is loaded and FALSE when it isn't

Declare at TOP of a MODULE before all subs (in Module1, Module2 etc)
Code:
Option Explicit

Public UserFormLoaded As Boolean

USERFORM code
Code:
Private Sub UserForm_Activate()
[COLOR=#006400]'when form is acivated[/COLOR]
    UserFormLoaded = True

End Sub

Private Sub CommandButton1_Click()

[COLOR=#006400]'when form is unloaded[/COLOR]
    UserFormLoaded = False
    Unload Me
End Sub
And then test the value of variable UserFormLoaded
Code:
If UserFormLoaded Then MsgBox "Loaded" Else MsgBox "Not Loaded"

This code does nothing if userform is not loaded
Code:
Userform1.Textbox1.Value = Target
 
Last edited:

Forum statistics

Threads
1,077,991
Messages
5,337,591
Members
399,156
Latest member
RaudMees

Some videos you may like

This Week's Hot Topics

Top