for next loop problem

EDUCATED MONKEY

Board Regular
Joined
Jul 17, 2011
Messages
218
Yet another up date can some one please tell me how I change this code so that when the conditions in each section of the if else block are satisfied that the “next” can see the “For” and not report the next without for if I can get this sorted then just maybe the other post will be come redundant
i sure that ther must be guys like my self stuck on this kind of thing I have looked and look through the forum nothing that fits the bill as most have been were end statements have been missed<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p></o:p>
For Position = WordLen To 1 Step -1 <o:p></o:p>
fwsp = True<o:p></o:p>
<o:p></o:p>
If MyChar = " " And fwsp = True Then<o:p></o:p>
fwsp = False<o:p></o:p>
Next Position<o:p></o:p>
ElseIf MyChar = " " And fwsp = False Then<o:p></o:p>
S = Replace(S, " ", "-")<o:p></o:p>
Next Position<o:p></o:p>
ElseIf MyChar <> " " And fwsp = False Then<o:p></o:p>
Next Position<o:p></o:p>
End If<o:p></o:p>
Next Position
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Thank you I realise that once the condition is true then the other two are false so I agree with what you said however it is still not achieving the goal of putting hyphens between the initials and not the surname <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
Original idea have a bool flip from true to false and check the along with the char in the string if thechar in the string = “ “ bool = true flip to false next time through loop the “ “ is Replace by “-“ so the result would be<o:p></o:p>
G K Aalborg changed to G-K Aalborg with no hyphen between the k and <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:eek:ffice:smarttags" /><st1:place>Aalborg</st1:place><o:p></o:p>
As it counts backwards I am wondering there is some anomily that I have over looked as it simply does not work and messing about with the false and true I cabn get G-K-Aalborg which is not the desired out come any ideas ?<o:p></o:p>
<o:p> </o:p>
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,321
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top