Need macro to place a portion of textbox into cell

nicolewh

Well-known Member
Joined
Aug 7, 2009
Messages
554
I need a macro to take the numbers between two symbols in a textbox - between the second "*" and the "+" and place these values in cell A1.

Example:
*123*456+

Result: values 456 in cell A1.

or when the "+" does no exist place only the values after the second "*"

Example:
*123*456

Result: values 456 in cell A1.

If it helps the "+", when used, is always on the end of the textbox.
and the second "*" is never used unless there are numbered values after it.
And, there could be between 3 and 5 values after the second *

Little crazy! I know

Thank you

Nicole
 
Last edited:

Some videos you may like

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,881
Hi Nicole

Try:

Code:
Range("A1") = Split(Replace(TextBox1.Value, "*", "+", 1, 2), "+")(2)
 

nicolewh

Well-known Member
Joined
Aug 7, 2009
Messages
554
Trying to adjust it to a change that I want.

instead of the * in the middle I want to use "-" instead.
example:
*123-456+

Result: 456

or
*123-456

Result: 456

How do I adjust it to do this?

Thanks!

Nicole
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,881
Hi again

If you mean from the first "-" to the end of the string (whether it has a "+" at the end or not), try:

Code:
Range("A1") = Split(Mid(TextBox1.Value, InStr(TextBox1.Value & "+", "-") + 1), "+")(0)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,499
Messages
5,596,517
Members
414,074
Latest member
Matthew Kakde

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