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))
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Trixterz

Board Regular
Joined
Aug 15, 2019
Messages
59
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
 

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
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)
 

Mikeymike_W

Board Regular
Joined
Feb 25, 2016
Messages
171
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,127,422
Messages
5,624,697
Members
416,042
Latest member
Oden

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
Top