Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Count spaces in front of text


Hi

Is it possible to count the number of spaces that appear before a text
in vba?

E.g. " Jean" = 3

I really would appreciate some help on this.

Thanks and Kind Regards


--
poppy
------------------------------------------------------------------------
poppy's Profile: http://www.excelforum.com/member.php...o&userid=11453
View this thread: http://www.excelforum.com/showthread...hreadid=558439

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Count spaces in front of text


Like this:

For i = 1 To Len(ActiveCell.Value)
If Mid(ActiveCell.Value, i, 1) < " " Then
MsgBox CStr(i - 1) & " spaces"
Exit For
End If
Next


Col


--
colofnature
------------------------------------------------------------------------
colofnature's Profile: http://www.excelforum.com/member.php...o&userid=34356
View this thread: http://www.excelforum.com/showthread...hreadid=558439

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Count spaces in front of text


*-Poppy on knees-* Thank you!!!! thank you! thank you! thank you! thank
you! Col

You're a life saver, I've been trying all day to figure this out. Thank
you so much.

Kind Regards


--
poppy
------------------------------------------------------------------------
poppy's Profile: http://www.excelforum.com/member.php...o&userid=11453
View this thread: http://www.excelforum.com/showthread...hreadid=558439

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Count spaces in front of text

Hi Poppy,

Try:

'=============
Public Sub Tester()
Const sStr As String = " Jean"
Dim iSpaces As Long

iSpaces = InStr(1, sStr, "J") - 1
MsgBox iSpaces
End Sub
'<<=============


---
Regards,
Norman


"poppy" wrote in
message ...

Hi

Is it possible to count the number of spaces that appear before a text
in vba?

E.g. " Jean" = 3

I really would appreciate some help on this.

Thanks and Kind Regards


--
poppy
------------------------------------------------------------------------
poppy's Profile:
http://www.excelforum.com/member.php...o&userid=11453
View this thread: http://www.excelforum.com/showthread...hreadid=558439



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Count spaces in front of text

And maybe a little more generic:

Option Explicit

Public Sub Tester()
Const sStr As String = " Jean"
Dim iSpaces As Long

iSpaces = InStr(1, sStr, Left(Trim(sStr), 1), vbTextCompare) - 1
MsgBox iSpaces
End Sub

Norman Jones wrote:

Hi Poppy,

Try:

'=============
Public Sub Tester()
Const sStr As String = " Jean"
Dim iSpaces As Long

iSpaces = InStr(1, sStr, "J") - 1
MsgBox iSpaces
End Sub
'<<=============

---
Regards,
Norman

"poppy" wrote in
message ...

Hi

Is it possible to count the number of spaces that appear before a text
in vba?

E.g. " Jean" = 3

I really would appreciate some help on this.

Thanks and Kind Regards


--
poppy
------------------------------------------------------------------------
poppy's Profile:
http://www.excelforum.com/member.php...o&userid=11453
View this thread: http://www.excelforum.com/showthread...hreadid=558439


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Count spaces in front of text


Got back to this one reviewing my watched threads..
If brevity is the watchword

MyCountOfSpaces=len(TheSTring)-len(ltrim(thestring)



Any better/more efficient methods



--
colofnatur
-----------------------------------------------------------------------
colofnature's Profile: http://www.excelforum.com/member.php...fo&userid=3435
View this thread: http://www.excelforum.com/showthread.php?threadid=55843

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Count spaces in front of text


Hi Guys

Thanks once again for all the help. Really appreciate it.

Kind Regards :)


--
poppy
------------------------------------------------------------------------
poppy's Profile: http://www.excelforum.com/member.php...o&userid=11453
View this thread: http://www.excelforum.com/showthread...hreadid=558439

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
remove spaces in front of text dolphin Excel Discussion (Misc queries) 2 October 8th 08 05:30 PM
blank spaces in front of a number prevents formatting cell Teri Excel Discussion (Misc queries) 2 April 10th 07 09:28 PM
How do I count cells with text but ignore cells with spaces? Husker87 Excel Discussion (Misc queries) 2 September 21st 06 12:31 AM
Removing 2 extra spaces in front of dates in imported excel doc Hannah Excel Discussion (Misc queries) 4 April 12th 06 07:37 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 11:34 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"