Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Count number of tab characters in a string

Whats a quick way to count the number of tab characters in a string variable?

-Robert
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Count number of tab characters in a string

Hi Robert,

Am Wed, 9 Oct 2019 03:49:14 -0700 (PDT) schrieb RG III:

What?s a quick way to count the number of tab characters in a string variable?


try:

i = Len(myStr) - Len(Replace(myStr, vbTab, ""))

where is is the number of tab characters


Regards
Claus B.
--
Windows10
Office 2016
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Count number of tab characters in a string

On Wednesday, October 9, 2019 at 4:22:33 AM UTC-7, Claus Busch wrote:

i = Len(myStr) - Len(Replace(myStr, vbTab, ""))


It does not work with the following code:

str1 = "Apples oranges cakes"
i = Len(str1) - Len(Replace(str1, vbTab, ""))
MsgBox "Number of tabs: " & i

There are 4 tabs in str1, but it returns 0. It appears that tab
characters are converted to space characters in the VBA editor.
Might that be the problem?
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 538
Default Count number of tab characters in a string

RG III wrote:

On Wednesday, October 9, 2019 at 4:22:33 AM UTC-7, Claus Busch wrote:

i = Len(myStr) - Len(Replace(myStr, vbTab, ""))


It does not work with the following code:

str1 = "Apples oranges cakes"
i = Len(str1) - Len(Replace(str1, vbTab, ""))
MsgBox "Number of tabs: " & i

There are 4 tabs in str1, but it returns 0. It appears that tab
characters are converted to space characters in the VBA editor.
Might that be the problem?


Yes. Try this:

str1 = "Apples" & vbTab & vbTab & "oranges" & vbTab & vbTab & "cakes"
i = Len(str1) - Len(Replace(str1, vbTab, ""))
MsgBox "Number of tabs: " & i

--
If you have an apple and I have an apple and we exchange apples then you and
I will still each have one apple. But if you have an idea and I have an idea
and we exchange these ideas, then each of us will have two ideas.
-- George Bernard Shaw
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
How can I count the number of characters on a cell? EddieDial800 Excel Discussion (Misc queries) 11 May 22nd 07 04:29 PM
Count characters within a string Francisco Excel Worksheet Functions 4 April 10th 07 05:28 PM
Count the number of characters created by string text [email protected] Excel Programming 6 January 19th 07 04:05 PM
trim a string by specific number of characters windyoldman Excel Discussion (Misc queries) 2 July 13th 05 01:53 PM
Count Number of Characters in a cell? AHJuncti Excel Discussion (Misc queries) 2 June 16th 05 07:39 PM


All times are GMT +1. The time now is 08:25 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"