Change Spaces to"_"

irresistible007

Board Regular
Joined
Nov 24, 2005
Messages
173
I have a text box, list Box and a cmd Button... clicking cmd button will add the Item typed in text box to List Box... BUT!!! i need to change any spaces to underscores, for instance if somebody typed "United Kingdom" and hit the add button then the item should appear like "United_Kingdom" in the List Box....

Any suggestions... though I know that the Chr function is the main ingredient but then how to look for positions and repeatitions?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
If you want to replace all spaces with underscores, try:

sItem = Replace(Trim(sItem), " ", "_")

Where sItem is the data from the textbox

You can then add sItem to the listbox.

Denis
 
Upvote 0
You could, but it's unnecessary. Replace does the job very efficiently by itself.

I added Trim in case anyone typed a space at the beginning or end.

Denis
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

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