LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Count tokens in a string

However, if you cannot be sure of this...

TokenCount = 1 + UBound(Split(WorksheetFunction.Trim(myVar)))


Hi Rick. This is a good solution. However, do you know if this code
can be transfered to MS Word VBA as well?? I'm not sure if
Word VBA uses the "WorksheetFunction" reference or not.


I don't program in Word, so I don't know for sure, but I would doubt it. Ron
seems more sure of this, so I will yield to his response. However, if you
don't want to set a reference to Excel, I would expect the following code to
work just fine in Word for the case where you are not sure of the number of
spaces between words...

Do While InStr(myVar, " ")
myVar = Replace(myVar, " ", " ")
Loop
TokenCount = 1 + UBound(Split(Trim(myVar)))

You should copy/paste the above rather than retype it so you don't miss the
double spaces between the first sets of quotes in the first two statements
(the second set of quotes contain only a single space).

Rick Rothstein (MVP - Excel)

 
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
seeking template to track tokens played in arcade game and payout arcademanager Setting up and Configuration of Excel 3 June 23rd 08 11:29 AM
Count string IF..... Coley Excel Worksheet Functions 4 August 21st 07 05:52 AM
Count characters within a string Francisco Excel Worksheet Functions 4 April 10th 07 05:28 PM
count in a string SHIRA Excel Programming 5 April 26th 06 08:07 PM
Count Spaces In A String Josh in Tampa Excel Programming 2 October 23rd 03 05:59 PM


All times are GMT +1. The time now is 06:47 PM.

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

About Us

"It's about Microsoft Excel"