Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For Next statement

why is it when i use this:
Function cvText(cllText As String)
For i = 1 To Len(cllText)
cvText = Mid(cllText, i, 1)
Next
End Function
....
and test it..
Print cvText("hello")
o
I get "o"
but if I use
Function cvText(cllText As String)
For i = 1 To Len(cllText)
cvText = Right(clltext,i)
Next
End Function
i get:
Print cvText("hello")
hello
i get "hello"

i want to be able to loop through each character
using mid(clltext,i,1) to test if there is a blank.

the goal is to create a function that ucase's the
beginning of each letter of a word
thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default For Next statement

cllText = StrConv(cllText, vbProperCase

--
Message posted from http://www.ExcelForum.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default For Next statement

Hi Vincent,

The function return value is whatever the last thing is that you
assigned to the function name. In the first case it was the last letter of
the input, in the second case it was all the letters of the input. I've
modified the first function below to return the entire input string:

Function cvText(cllText As String)
Dim i As Long
For i = 1 To Len(cllText)
cvText = cvText & Mid(cllText, i, 1)
Next i
End Function

Note that with each pass through the loop the additional character is being
concatenated onto the previous characters, rather than replacing them as in
the original.

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *


"vincentj" wrote in message
...
why is it when i use this:
Function cvText(cllText As String)
For i = 1 To Len(cllText)
cvText = Mid(cllText, i, 1)
Next
End Function
...
and test it..
Print cvText("hello")
o
I get "o"
but if I use
Function cvText(cllText As String)
For i = 1 To Len(cllText)
cvText = Right(clltext,i)
Next
End Function
i get:
Print cvText("hello")
hello
i get "hello"

i want to be able to loop through each character
using mid(clltext,i,1) to test if there is a blank.

the goal is to create a function that ucase's the
beginning of each letter of a word
thanks.



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
IF statement inside a SUMIF statement.... or alternative method Sungibungi Excel Worksheet Functions 3 December 4th 09 06:22 PM
Reconcile Bank statement & Credit card statement & accounting data Bklynhyc Excel Worksheet Functions 0 October 7th 09 09:07 PM
Embedding an OR statement in an IF statement efficiently Chatnoir11 Excel Discussion (Misc queries) 4 February 2nd 09 08:12 PM
Sum if statement with a left statement Eric D Excel Discussion (Misc queries) 4 July 23rd 08 05:31 PM
appending and IF statement to an existing IF statement spence Excel Worksheet Functions 1 February 28th 06 11:00 PM


All times are GMT +1. The time now is 03:45 AM.

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"