ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Count number of tab characters in a string (https://www.excelbanter.com/excel-programming/454468-count-number-tab-characters-string.html)

RG III

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

-Robert

Claus Busch

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

RG III

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?

Auric__

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


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

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