Copy Partial text in Userform Textbox

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
Hi,

I am wanting to copy the text from a Userform Textbox (TBRand) to another textbox (TBRandB) on the same userform.
The thing is I only want to copy over the text that occurs before the hyphon (-).

I found this bit of code which does it for a worksheet but i'm not sure how to adapt this for a userform textbox.

I appreciate any help you can give me,

Mike

VBA Code:
Dim ws As Worksheet
Set ws = Worksheets("Analysis")

ws.Range("C5") = Left(ws.Range("B5"), (Application.WorksheetFunction.Find("-", ws.Range("B5"), 1) - 1))
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try copying the value directly from the TextBox itself by using whatever name you assigned to the TextBox itself.

VBA Code:
Me.TBRandB.Value = TBRand.Value
 
Upvote 0
The thing is I only want to copy over the text that occurs before the hyphen (-)

How about ...

VBA Code:
   Dim t As String
   t = Me.TBRand.Text
   If InStr(t, "-") > 0 Then tTBRandB.Text = Split(t, "-")(0)
 
Upvote 0
How about ...

VBA Code:
   Dim t As String
   t = Me.TBRand.Text
   If InStr(t, "-") > 0 Then tTBRandB.Text = Split(t, "-")(0)
Yongle, thanks very much for your help, this seems to have done the job. Wee typo and missing and "End IF" but once that was sorted it did just as I wanted.

Thank you very much!
 
Upvote 0

Forum statistics

Threads
1,214,791
Messages
6,121,611
Members
449,038
Latest member
apwr

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