Adding code

M

MAX

Hello
I have this code (below) and I wish to add another Interior.ColorIndex and
another Value, what code I have to add and where I have to insert it?

Option Explicit
Dim nextSecond

Sub startFlashing()
flashCell
End Sub

Sub stopFlashing()
On Error Resume Next
Application.OnTime nextSecond, "flashCell", , False
End Sub

Sub flashCell()
nextSecond = Now + TimeValue("00:00:01")
Application.OnTime nextSecond, "flashCell"


If Range("D7").Interior.ColorIndex = 4 Then
Range("D7").Interior.ColorIndex = 5
Range("D7").Value = "SPORT"

ElseIf Range("D7").Interior.ColorIndex = 5 Then
Range("D7").Interior.ColorIndex = 3
Range("D7").Value = "EDUCATION"

ElseIf Range("D7").Interior.ColorIndex = 3 Then
Range("D7").Interior.ColorIndex = 4
Range("D7").Value = "Media"

Else
'to kick it all off
Range("D7").Interior.ColorIndex = 4
Range("D7").Value = "Media"

End If
End Sub

Thanks in advance.
 
P

p45cal

one way:

VBA Code:
--------------------


Sub flashCell()
nextSecond = Now + TimeValue("00:00:01")
Application.OnTime nextSecond, "flashCell"
If Range("D7").Interior.ColorIndex = 4 Then
Range("D7").Interior.ColorIndex = 5
Range("D7").Value = "SPORT"

ElseIf Range("D7").Interior.ColorIndex = 6 Then
Range("D7").Interior.ColorIndex = 4
Range("D7").Value = "Media"

ElseIf Range("D7").Interior.ColorIndex = 5 Then
Range("D7").Interior.ColorIndex = 3
Range("D7").Value = "EDUCATION"

ElseIf Range("D7").Interior.ColorIndex = 3 Then
Range("D7").Interior.ColorIndex = 6
Range("D7").Value = "NEW ONE"

Else
'to kick it all off
Range("D7").Interior.ColorIndex = 4
Range("D7").Value = "Media"
End If
End Sub

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



but it might be easier to adjust later if you do it thus:


VBA Code:
--------------------


Sub flashCell()
nextSecond = Now + TimeValue("00:00:01")
Application.OnTime nextSecond, "flashCell"
With Range("D7")
Select Case .Interior.ColorIndex

Case 3
.Interior.ColorIndex = 6
.Value = "NEW ONE"

Case 4
.Interior.ColorIndex = 5
.Value = "SPORT"

Case 5
.Interior.ColorIndex = 3
.Value = "EDUCATION"

Case 6
.Interior.ColorIndex = 4
.Value = "Media"

Case Else
'to kick it all off
.Interior.ColorIndex = 4
.Value = "Media"

End Select
End With
End Sub
 
O

OssieMac

Hi Max,

I would use Select Case. That way it is easy to just add another case
statement.

Sub flashCell()
nextSecond = Now + TimeValue("00:00:01")
Application.OnTime nextSecond, "flashCell"

Select Case Range("D7").Interior.ColorIndex
Case 4
Range("D7").Interior.ColorIndex = 5
Range("D7").Value = "SPORT"

Case 5
Range("D7").Interior.ColorIndex = 3
Range("D7").Value = "EDUCATION"

Case 3
Range("D7").Interior.ColorIndex = 4
Range("D7").Value = "Media"

Case Else
'to kick it all off
Range("D7").Interior.ColorIndex = 4
Range("D7").Value = "Media"

End Select

End Sub
 

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

Adding code 5
Arrange code 3
Compile error 7
Code arrangement 3
2 codes in one sheet 5
Code help 6
Flashing cells 5
Code error 5

Top