ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Case Statement error (https://www.excelbanter.com/excel-programming/302209-case-statement-error.html)

David Adamson[_3_]

Case Statement error
 
What I am trying to do is show a series of 6 images (Area) who's background
colour changes depending upon the value in a table (5 choices for colour).
What is happening here is that it is reading in 10 years of data and then
checking to see what that value is for the 6 images and then based on its
value it should give me the appropriate colour. I can get the background
colour to change but not correctly.



What is happening is that one the value is 0 it bails out on the second
case statement

Case 0 To choice1 ' choice1 '.Value

Results("Area" & j).BackColor = Colour2



I think this is because at Values = 20 but at choice = "20"



I'm not to sure how to get around this but I'm sure I haven't defined
something right and my brain has died



Secondly how do I delay the macro (by one or two seconds) at the Next i
stage so that you can see what happens to each image for each column of
data.



Thanks in advance





Private Sub RunALL_Click()

'Dim Year As Interger

Dim Area As Image

'Dim choice As b

Dim i, j As Integer



'set colours

Colour1 = vbWhite

Colour2 = C1.BackColor

Colour3 = c2.BackColor

Colour4 = c3.BackColor

Colour5 = vbBlack



'10 year's worth of data to evaluate

For i = 1 To 10

Year.Caption = Format("Year" & i)

For j = 1 To 6

With Worksheets("Amount")

'image value

Values = Cells(2 + j, 1 + i) '.value

End With



Select Case Values

Case 0

Results("Area" & j).BackColor = Colour1

Case 0 To choice1 ' choice1 '.Value

Results("Area" & j).BackColor = Colour2

Case choice1 To choice2

Results("Area" & j).BackColor = Colour3

Case choice2 To choice3

Results("Area" & j).BackColor = Colour4

Case Is choice3



Results("Area" & j).BackColor = Colour5



End Select

Next j

DoEvents

Next i



End Sub



mudraker[_273_]

Case Statement error
 
Use Pause command or Wait command

Application.Wait Now() + TimeValue("00:00:10")


sub dddd
your commands

pause

or

Application.Wait Now() + TimeValue("00:00:10")

more commands

end sub


Re Your case problem if you have not declared you variables I sugges
you do declare them and have
Option Explicit
as the very first entry on you module sheet before trying to sort ou
your proble

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


David Adamson[_3_]

Case Statement error
 
Thanks mudraker problems solved

I juist wasn't thinking about Dim was I?





All times are GMT +1. The time now is 07:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com