Show content of a userform textbox

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
Hello All,
I have two textboxes on my userform and i want to put start date and end date in them. Then the next thing i wanna do is that those two dates should be set to two cells on my worksheet say A5 and B5. And anytime i load the form, i want those dates back in the textboxes. The textboxes are named tb1 and tb2. I am struggling to figure out how to do it then i remembered that someone always knows more than i do so i have come for help.
Thanks
Kelly
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Hi,

try:

Place code in your forms code page.
Rich (BB code):
Private Sub UserForm_Initialize()
    With Sheets("Sheet1")
        Me.tb1.Text = .Range("A5").Text
        Me.tb2.Text = .Range("B5").Text
    End With
End Sub

Change sheet name shown in RED as required.

Dave
 
Upvote 0
Okay. Thanks . But how do i take the data in the textboxes to the sheet?
I wanna use the tb_update event
 
Last edited:
Upvote 0
Okay i think something like this will do that trick i want
Code:
Private Sub tb1_Update()
    With Sheets("Sheet1")
        .Range("A5").Text = Me.tb1.Text
    End With
End Sub
 
Upvote 0
Hi,

try

Rich (BB code):
Dim ws As Worksheet


Private Sub tb1_AfterUpdate()
If IsDate(Me.tb1.Text) Then
    ws.Range("A5").Value = DateValue(Me.tb1.Text)
End If
End Sub


Private Sub tb2_AfterUpdate()
If IsDate(Me.tb2.Text) Then
    ws.Range("B5").Value = DateValue(Me.tb2.Text)
End If
End Sub


Private Sub UserForm_Initialize()
    Set ws = Sheets("Sheet1")
    Me.tb1.Text = ws.Range("A5").Text
    Me.tb2.Text = ws.Range("B5").Text
End Sub

Note the ws variable which MUST sit at TOP of your forms code page OUTSIDE any procedure.

Dave
 
Last edited:
Upvote 0
Thanks a lot. I have not tested them yet but have looked at the codes and i do understand whatever is going on in them. Will try them very soon when i get home.

Before then, i am very grateful
Kelly
 
Upvote 0
Thanks a lot. I have not tested them yet but have looked at the codes and i do understand whatever is going on in them. Will try them very soon when i get home.

Before then, i am very grateful
Kelly

most welcome - hope helps

Dave
 
Upvote 0
I have a problem inserting the macro
into mine
Code:
Dim ws As Worksheet


Private Sub tb1_AfterUpdate()
If IsDate(Me.tb1.Text) Then
    ws.Range("A5").Value = DateValue(Me.tb1.Text)
End If
End Sub


Private Sub tb2_AfterUpdate()
If IsDate(Me.tb2.Text) Then
    ws.Range("B5").Value = DateValue(Me.tb2.Text)
End If
End Sub


Private Sub UserForm_Initialize()
    Set ws = Sheets("Sheet1")
    Me.tb1.Text = ws.Range("A5").Text
    Me.tb2.Text = ws.Range("B5").Text
End Sub

The macro in my project is as below:
Code:
Sub UserForm_Initialize()
    cmb.AddItem "one"
    cmb.AddItem "two"
    cmb.AddItem "three"
End Sub

Private Sub cmb_Click()
    Select Case cmb.Value
       Case "one"
       cmb1.AddItem "Sheet1"
        Case "two"
       cmb1.AddItem "Sheet2"
       Case "three"
       cmb1.AddItem "Sheet3"
    End Select
End Sub

I am finding it tough to get it into my macro.
 
Upvote 0

Forum statistics

Threads
1,214,957
Messages
6,122,466
Members
449,086
Latest member
kwindels

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