Compile Error. Else without If?

G

Guest

I'll post my macro below, but the question is, why am I getting an error?

Says that theres an Else without an IF, but I have 2 elses and 2 ifs. One
for each one?

Sub Button2_Click()

Dim col As Variant
Dim rang As Variant
Dim col2 As Variant
Dim end1 As Variant

end1 = 1

Range("C3").Select
ActiveCell.FormulaR1C1 = "1"
Range("D3").Select

Do Until end1 = 8000


rang = Range("E3").Value
col = Range(rang).Value

Range(rang).Select

If col < 100 Then

With Selection.Interior
.ColorIndex = col
.Pattern = xlSolid
End With
Selection.Font.ColorIndex = col

Else

If col = 104 Then

With Selection.Interior
.ColorIndex = 3
.Pattern = xlGray25
.PatternColorIndex = xlAutomatic
Selection.Font.ColorIndex = 3

Else

col2 = col - 100

With Selection.Interior
.ColorIndex = col2
.Pattern = xlGray8
.PatternColorIndex = xlAutomatic

Selection.Font.ColorIndex = col2

End If
End If



Range("D3").Select
Selection.Copy
Range("C3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False

end1 = Range("C3").Value


Loop

End Sub
 
B

Bob Umlas

You have 2 (count 'em, 2) missing lines:
End With
See where I've indicated you need them in your code below
 
S

stevebriz

Paul,
There is many erros in this...can you explain what you are trying to do
and then I will try to help you???
 
G

Guest

Cheers, to be honest, I don't know what all this "with" and "end with" stuff
is, I must have just copied the recorded macro incorrectly :p
 
G

Guest

I need to colour cells in several colours, unfortunatly Conditional
Formatting can only be used 3 times.

I down loaded an addin from this forum, but it error, and I figured I'd do a
macro instead.

Each cell contains a value (which corresponds to a colour) the macro runs
through the numbers 1 to 8000, each number turning into a Cell reference via
formulas on the page. Starts at A1, switches to B1 after A167.

The macro then looks into the cell its selected for the number, and colours
the cell and the text in that colour.
 
S

stevebriz

Paul,
There is only 56 colors when using colorindex.

So In you code above ir refers to color the cell the color of the
number if the cell if less than 100 ( this will cause error- as this
will one the cell value is greater than 56)

It has another case if the cell value is 104 then the colorindex is 3 (
Red)
The if the cell value is soething else it say that the color of the
cell value will be the cell.value - 100. This will only work for cells
with values of 101 to 156.

So here is the question. What do you want to see?
56 colors repeated for 8000 cells number 1 -8000 in cells A1 to AV103?
 

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


Top