Setting Userform textbox value from Worksheet_Change

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
661
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
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
5,257
Office Version
365
Platform
Windows
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,089,431
Messages
5,408,183
Members
403,188
Latest member
Sanjana Ramesh

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top