usfrom value

nada

Board Regular
Joined
Jul 4, 2006
Messages
193
I have a userform that when is shown when the user clicks a button. When the userforms opens I want to show a number in a textfield. However that fails and the field shows nothing. The number is found in a cell and the number is then read in to a variable that is to be shown in the userform. Pls help me with this problem.

Private Sub UserForm1_Initialize()
Set rngErrorMarginCell = Range("d5")
dblErrorMarginal = rngErrorMarginCell.Value
TextBox1.Text = dblErrorMarginal
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi,

I think you missing the sheet name in which the range is present. Try this:

Changes are in bold.

Private Sub UserForm1_Initialize()
Set rngErrorMarginCell = Sheets(<sheet name>). Range("d5")
dblErrorMarginal = rngErrorMarginCell.Value
TextBox1.Text = dblErrorMarginal
End Sub
_________________
 
Upvote 0
show number in textbox

Hello! Ok my problem is:

1) I seem to fail to show any text in the textbox when the userfrom is inintialized. Thus i wonder if it is possible to show a numer/text in a textbox when the userform is shown?

2) If it is possible what am I doing wrong here? I just cannot seem to se what is the problem..
3) If it is not possible is there any tips for going around the problem.

I simplyfied my code to :

Sub UserForm1_Initialize()
Me.TextBox1.Text = "Hello World!"
End Sub

but that did not work....pls help me!
 
Upvote 0
Hi,

the reason is very simple
you don't need the name of the userform in your code
NOT
Code:
Sub UserForm1_Initialize()
but the "general expression"
Code:
Sub UserForm_Initialize()

kind regards,
Erik
 
Upvote 0
Thanks!

Hello erik.van.geit! Thank you very much for your reply! You were quite correct and it works fine now. Many. many thanks!
 
Upvote 0
you're welcome :)

think about it like
Code:
Private Sub Worksheet_Activate()

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub
you wouldn't write
Code:
Private Sub Worksheet1_....
kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,203,044
Messages
6,053,186
Members
444,643
Latest member
Shipwreck818

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top