Complex problem involving VBA in excel

Joined
Jun 24, 2005
Messages
10
Reaction score
0
Sorry if this might sound familiar to some of you but I hope someone can help me with some 'challenges'.

I’m trying to create a nice-looking interactive worksheet. I have obtained two vba programs from some free websites. This first one lets my cell blink white and purple. Originally it was to make many cells do that and in multiple colours but I’ve edited it and I’m not sure if there is any unnecessary lines of code in it. Also, I have a problem, when I quit it closes my whole excel application (including other worksheets). If I say cancel with regard to saving in other worksheets, for some reason my blinking work sheets re-opens itself (it will keep doing so unless I disable macros).
Below is the code for the blinking cell (code for ThisWorkBook and code in a Module):


----------------ThisWorkBook----------

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.Quit
End Sub


Private Sub Workbook_Open()

Call Blink

End Sub



----------------module---------------


Dim BlinkTime As Date

Public Sub Blink()
Dim c As Range

For Each c In Range("C3").Cells
If c.Interior.ColorIndex = 47 Then
If c.Value > 100 Then
c.Interior.ColorIndex = 2 'White
ElseIf c.Value > 50 Then
c.Interior.ColorIndex = 2 'White
Else
c.Interior.ColorIndex = 2 'White
End If
Else
c.Interior.ColorIndex = 47
End If
Next c


BlinkTime = Now() + TimeValue("00:00:01")
Application.OnTime BlinkTime, "Blink"
End Sub


In addition, I have another vba program code that basically highlights the row of the selected cell. It works really well because it restores the any previous colours in cells after I’ve moved it elsewhere. However if I save the work sheet before quitting, it saves the highlighted row. The code for this is listed below (I keep it in Sheet 9 which is called REPORT).



---------------------Sheet9 (REPORT)----------------

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Const cnNUMCOLS As Long = 256
Const cnHIGHLIGHTCOLOR As Long = 38 'default lt. blue
Static rOld As Range
Static nColorIndices(1 To cnNUMCOLS) As Long
Dim i As Long
If Not rOld Is Nothing Then 'Restore color indices
With rOld.Cells
If .Row = ActiveCell.Row Then Exit Sub 'same row, don't restore
For i = 1 To cnNUMCOLS
.Item(i).Interior.ColorIndex = nColorIndices(i)
Next i
End With
End If
Set rOld = Cells(ActiveCell.Row, 1).Resize(1, cnNUMCOLS)
With rOld
For i = 1 To cnNUMCOLS
nColorIndices(i) = .Item(i).Interior.ColorIndex
Next i
.Interior.ColorIndex = cnHIGHLIGHTCOLOR
End With
End Sub


What I’d like to do:

1. Get my worksheet to quit properly with regard to the blinking cell.
2. Make the row highlighting only applicable to rows 7 to 100 in my worksheet.
3. Prevent my worksheet from saving the highlighted row after save.
4. Combine both the blinking cell and row highlighting into the same worksheet.


Is it correct to assume that the blinking cell and row highlight programs cannot work if the worksheet is protected?

Thanks in advance to anyone who can figure all of the above out! (I know it’s quite a lot).

FD
 

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

Top