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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,223,912
Messages
6,175,341
Members
452,638
Latest member
Oluwabukunmi

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