ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Trim not working (https://www.excelbanter.com/excel-programming/329552-trim-not-working.html)

Stuart[_21_]

Trim not working
 
User enters their data on the form then clicks ok.
A sub executes, and initially I use trim on some of the
textboxes eg:

With FrmDataEntry
UsrName = Trim(.TbUsrName)
which doesn't work...and tried
UsrName = Trim(.TbUsrName.Value)
which doesn't work either.

However, this statement which is executed from a different form's click
event does work:

If Trim(Userform1.TextBox1) = "" Then

Education please!

Regards.



Stuart[_21_]

Trim not working
 
Might be useful if I mentioned the required end result(g),
namely to remove leading, trailing and intermediate spaces from the string.
Apologies.

"Stuart" wrote in message
...
User enters their data on the form then clicks ok.
A sub executes, and initially I use trim on some of the
textboxes eg:

With FrmDataEntry
UsrName = Trim(.TbUsrName)
which doesn't work...and tried
UsrName = Trim(.TbUsrName.Value)
which doesn't work either.

However, this statement which is executed from a different form's click
event does work:

If Trim(Userform1.TextBox1) = "" Then

Education please!

Regards.




JE McGimpsey

Trim not working
 
VBA's Trim() function, unlike XL's TRIM(), doesn't remove internal
spaces. Is that's what's not working?

You could try:

UsrName = Application.Trim(.TbUsrName)



In article ,
"Stuart" wrote:

Might be useful if I mentioned the required end result(g),
namely to remove leading, trailing and intermediate spaces from the string.


Stuart[_21_]

Trim not working
 
Many thanks, but had tried that with a little, but not complete luck eg, if
the user string was:
sgb test 1 (ie loads of spaces) then
Application.Trim seems to result in:
sgb test 1 (ie one space between each element of the original string)
Is that the intended result?

For my purposes, I'm looking to reduce the user's data string to one
containing no 'spaces' whatsoever.

Regards.

"JE McGimpsey" wrote in message
...
VBA's Trim() function, unlike XL's TRIM(), doesn't remove internal
spaces. Is that's what's not working?

You could try:

UsrName = Application.Trim(.TbUsrName)



In article ,
"Stuart" wrote:

Might be useful if I mentioned the required end result(g),
namely to remove leading, trailing and intermediate spaces from the
string.




Toppers

Trim not working
 
Try

usrName=Replace(usrName," ","")

HTH

"Stuart" wrote:

Many thanks, but had tried that with a little, but not complete luck eg, if
the user string was:
sgb test 1 (ie loads of spaces) then
Application.Trim seems to result in:
sgb test 1 (ie one space between each element of the original string)
Is that the intended result?

For my purposes, I'm looking to reduce the user's data string to one
containing no 'spaces' whatsoever.

Regards.

"JE McGimpsey" wrote in message
...
VBA's Trim() function, unlike XL's TRIM(), doesn't remove internal
spaces. Is that's what's not working?

You could try:

UsrName = Application.Trim(.TbUsrName)



In article ,
"Stuart" wrote:

Might be useful if I mentioned the required end result(g),
namely to remove leading, trailing and intermediate spaces from the
string.





Stuart[_21_]

Trim not working
 
Seems the answer. Many thanks.
Regards.

"Toppers" wrote in message
...
Try

usrName=Replace(usrName," ","")

HTH

"Stuart" wrote:

Many thanks, but had tried that with a little, but not complete luck eg,
if
the user string was:
sgb test 1 (ie loads of spaces) then
Application.Trim seems to result in:
sgb test 1 (ie one space between each element of the original
string)
Is that the intended result?

For my purposes, I'm looking to reduce the user's data string to one
containing no 'spaces' whatsoever.

Regards.

"JE McGimpsey" wrote in message
...
VBA's Trim() function, unlike XL's TRIM(), doesn't remove internal
spaces. Is that's what's not working?

You could try:

UsrName = Application.Trim(.TbUsrName)



In article ,
"Stuart" wrote:

Might be useful if I mentioned the required end result(g),
namely to remove leading, trailing and intermediate spaces from the
string.








All times are GMT +1. The time now is 09:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com