If Next

D

Dave Neve

Hi

A few months ago sm in the group gave me a simple bit of code to change the
colour and spacing of a selected word.

I would like to expand the code slightly to take into account the length of
the word.(different lengths, different font sizes) so I added an If
statement and I now have the partial code below but it blocks on the 'next
i' line (what a surprise!!!)

VB says 'Next without for' but there is a 'For' statement so I don't know
what to do

While I am at it, I'd also like to know how you type the mathematical
operators like < which are not on the keyboard.

I am currently copying and pasting them as and when I need them but there
must be a better way?

Thanks in advance



Dim wordrange As Range, lrange As Range, i As Long, j As Long
Set wordrange = Selection.Range


j = 2

For i = 1 To wordrange.Characters.Count
Set lrange = wordrange.Characters(i)
If Selection.Words.Count <= 4 Then
lrange.Font.Size = 8
lrange.Font.Size = lrange.Font.Size + j
j = j + 2
lrange.Font.Spacing = 5
wordrange.Font.Color = wdColorTan


Next i

Else
 
J

Jason Eacott

you need a matching end if, and you cant overlap control blocks.

Dim wordrange As Range, lrange As Range, i As Long, j As Long
Set wordrange = Selection.Range
j = 2

For i = 1 To wordrange.Characters.Count
Set lrange = wordrange.Characters(i)
If (Selection.Words.Count <= 4) Then
lrange.Font.Size = 8
lrange.Font.Size = lrange.Font.Size + j
j = j + 2
lrange.Font.Spacing = 5
wordrange.Font.Color = wdColorTan
else
something ...
end if
Next i

and what do you mean < is not on the keyboard? how did u type it here?
its on top of the comma on a qwerty keyboard.
 
D

Dave Neve

Hi

Thanks for the help but I am gobsmacked and sick to death with VB

I thought I understood your code and could finish it off with

Sub RisingLong()

Dim wordrange As Range, lrange As Range, i As Long, j As Long
Set wordrange = Selection.Range

j = 2

For i = 1 To wordrange.Characters.Count
Set lrange = wordrange.Characters(i)

If Selection.Words.Count <= 4 Then
lrange.Font.Size = 8
lrange.Font.Size = lrange.Font.Size + j
j = j + 2
lrange.Font.Spacing = 5
wordrange.Font.Color = wdColorTan

Else
lrange.Font.Size = 8
lrange.Font.Size = lrange.Font.Size + j
j = j + 1
lrange.Font.Spacing = 5
wordrange.Font.Color = wdColorTan


End If
Next i


----------------------------------------------------------

I assumed that 'else' must cover 5 or more characters.

Here's the crunch. The code runs but it doesn't seem to matter if I select a
word with 3 or 5 characters.

Each word starts off with a character of size font 8 and each subsequent
character goes up by 2 sizes !!!!!!

I have other questions as well but I've put them on hold.

Thanks in advance again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top