#1   Report Post  
Posted to microsoft.public.excel.programming
Max Max is offline
external usenet poster
 
Posts: 390
Default Adding code

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Adding code


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
--------------------





MAX;704585 Wrote:

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.



--
p45cal

*p45cal*
------------------------------------------------------------------------
p45cal's Profile: http://www.thecodecage.com/forumz/member.php?u=558
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=197145

http://www.thecodecage.com/forumz

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Adding code

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


--
Regards,

OssieMac


"MAX" wrote:

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.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding code MAX Excel Programming 5 April 20th 10 02:02 AM
Creating excel file, adding code to it from code, VBE window stays BlueWolverine Excel Programming 0 November 5th 09 07:55 PM
adding code lines with vba code thread Excel Programming 4 February 6th 08 01:31 PM
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. Corey Excel Programming 3 December 11th 06 05:14 AM
adding to a VBA COde diacci1st Excel Programming 0 November 23rd 06 11:21 AM


All times are GMT +1. The time now is 08:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"