Else without if?

D

davegb

More code, this time getting an "Else without if" error at the else
line!

Range("a1").Select
Set TtlRng = Range(Selection, Selection.End(xlToRight))
For Each rFoundHd In TtlRng.Cells
If Right(rFoundHd.Value, 2) = "ID" Then
ActiveSheet.Range(rFoundHd,
rFoundHd.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlRight
.NumberFormat = "@"
Else
Next rFoundHd
End If

Sure looks like an "If" to me, 6 lines above the else!
rFoundHd is declared as a range, as is TtlRng.
The code is supposed to look in row 1 for any header ending in "ID".
When it finds one, it should format that column to text and right align
it. Then move to the next cell in row 1.
Any suggestions?
Thanks in advance.
 
C

Charlie

It also looks like you have a For-Next structure error. Try:

For Each rFoundHd In TtlRng.Cells
If Right(rFoundHd.Value, 2) = "ID" Then
ActiveSheet.Range(rFoundHd, rFoundHd.End(xlDown)).Select
With Selection
.HorizontalAlignment = xlRight
.NumberFormat = "@"
End With
Exit For
End If
Next rFoundHd
 

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

Similar Threads

Yet another error 3
block variable not set? 4
Remove Identical words 0
Printing issue 1
help needed with borders 2
Subtotal Formatting 2
Looping through Worksheets_(excluding one) 4
VB Printing problem 0

Top