Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Is there a VBE constant for NBSP (Chr 160)?

Thanks,
George


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Is there a VBE constant for NBSP (Chr 160)?

I don't think so. Why not just declare it in your code?
--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Is there a VBE constant for NBSP (Chr 160)?

There is no built in constant for that character (constants exist only
for chars 1-127 with a few exceptions). You can declare a Public
variable to hold the character.

' In Module1
Public NBSP As String

' In ThisWorkbook
Private Sub Workbook_Open()
NBPS=Chr(160)
End Sub

Another way, which is in fact better, is to use Property in Module1
(yes, normal code modules can have properties).

Public Property Get NBSP() As String
NBSP = Chr(160)
End Property

Then, in another procedu

Dim S As String
S = "abc" & NBSP & "def"
Dim N As Long
N = InStr(1, S, NBSP)
Debug.Print N 'Displays 4

The advantage of using a property rather than a public variable is
that if your code terminates with an error or an End statement is
encountered, or VBA just decides to recompile the project, Public
variables are dumped, so the public variable would revert to an empty
string, no longer containing Chr(160). With a property as shown above,
it will always return Chr(160) regardless of what VBA decides to do.




Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Mon, 15 Feb 2010 21:21:51 -0700, "G Lykos"
wrote:

Thanks,
George

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Is there a VBE constant for NBSP (Chr 160)?

Another way, or as I think Ron was suggesting

Public Const NBSP As String = " " ' chr(160)

Sub test()
Debug.Print Asc(NBSP) ' 160
End Sub

I got the space like character between the quotes from this in the
Intermediate window
?chr(160)

Regards,
Peter T



"G Lykos" wrote in message
...
Thanks,
George




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Is there a VBE constant for NBSP (Chr 160)?

Interesting, I definitely posted the constant as a chr(160), but it appears
as a normal space chr(32). So don't simply copy/paste the example, make your
own along the lines suggested.

Regards,
Peter T

"Peter T" <peter_t@discussions wrote in message
...
Another way, or as I think Ron was suggesting

Public Const NBSP As String = " " ' chr(160)

Sub test()
Debug.Print Asc(NBSP) ' 160
End Sub

I got the space like character between the quotes from this in the
Intermediate window
?chr(160)

Regards,
Peter T



"G Lykos" wrote in message
...
Thanks,
George








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Is there a VBE constant for NBSP (Chr 160)?

Thanks for the guidance!


"Chip Pearson" wrote in message
...
There is no built in constant for that character (constants exist only
for chars 1-127 with a few exceptions). You can declare a Public
variable to hold the character.

' In Module1
Public NBSP As String

' In ThisWorkbook
Private Sub Workbook_Open()
NBPS=Chr(160)
End Sub

Another way, which is in fact better, is to use Property in Module1
(yes, normal code modules can have properties).

Public Property Get NBSP() As String
NBSP = Chr(160)
End Property

Then, in another procedu

Dim S As String
S = "abc" & NBSP & "def"
Dim N As Long
N = InStr(1, S, NBSP)
Debug.Print N 'Displays 4

The advantage of using a property rather than a public variable is
that if your code terminates with an error or an End statement is
encountered, or VBA just decides to recompile the project, Public
variables are dumped, so the public variable would revert to an empty
string, no longer containing Chr(160). With a property as shown above,
it will always return Chr(160) regardless of what VBA decides to do.




Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]



On Mon, 15 Feb 2010 21:21:51 -0700, "G Lykos"
wrote:

Thanks,
George



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Is there a VBE constant for NBSP (Chr 160)?

Thanks!


"Peter T" <peter_t@discussions wrote in message
...
Interesting, I definitely posted the constant as a chr(160), but it
appears as a normal space chr(32). So don't simply copy/paste the example,
make your own along the lines suggested.

Regards,
Peter T

"Peter T" <peter_t@discussions wrote in message
...
Another way, or as I think Ron was suggesting

Public Const NBSP As String = " " ' chr(160)

Sub test()
Debug.Print Asc(NBSP) ' 160
End Sub

I got the space like character between the quotes from this in the
Intermediate window
?chr(160)

Regards,
Peter T



"G Lykos" wrote in message
...
Thanks,
George








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Is there a VBE constant for NBSP (Chr 160)?

Right.


"Ron Rosenfeld" wrote in message
...
I don't think so. Why not just declare it in your code?
--ron



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
TrimAll ; $nbsp; alt+0160; Cell View Add-In LiCal Excel Programming 2 July 15th 08 06:02 PM
removing nbsp character Geoff Ness Excel Discussion (Misc queries) 5 January 11th 07 05:41 AM
char(160) - &nbsp; Biff Excel Worksheet Functions 8 October 18th 06 09:02 AM
&nbsp; Aaron[_13_] Excel Programming 1 May 5th 04 06:25 PM
&nbsp in Excel Aaron[_13_] Excel Programming 2 April 29th 04 04:06 PM


All times are GMT +1. The time now is 01:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"