LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Cannot find inefficient coding loop

Please help,
I have an Excel workbook to schedule work for employees. The
"Schedule" sheet has 80 rows of employee names and 180 columns of
daily work codes. The "Codes" sheet has one column of approved
codes listed in specific colors. When a work code is entered in a cell
on the "Schedule" sheet, I want Excel to check to ensure it is an
approved code and then display it using the color and font formatting
from the "Codes" sheet. An unapproved code should just paint the
cell red and leave it empty.

The sub listed below works (except painting errors red), but it must
have an inefficient error somewhere. If I use the MsgBox's listed to
trap errors, it gives the right data, but repeats the MsgBoxes hundreds
of times before finishing. What am I doing wrong and is there a more
efficient way of accomplishing this?

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Count = 1 Then
If Not Intersect(Target, Range("c7:iv100")) Is Nothing Then
Target.Value = UCase(Target.Value)
End If
End If

With Worksheets("Codes").Range("a1:a50")
Set c = .Cells.Find(What:=Target.Value, _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not c Is Nothing Then
CodeAddress = c.Address
SchedCode = c.Value
SchedColor = c.Interior.ColorIndex
SchedFont = c.Font.ColorIndex
Else:
MsgBox (Target.Value & " is not an approved code")
Target.Value = Null
SchedColor = 3 'paint red
End If
End With

MsgBox ("code address is " & CodeAddress)
MsgBox ("target value is " & SchedCode)
MsgBox ("target interior color is " & SchedColor)
MsgBox ("target font color is " & SchedFont)

Target.Interior.ColorIndex = SchedColor
Target.Font.ColorIndex = SchedFont

End Sub

 
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
How do I change the color coding with Find & Replace? JimG Excel Discussion (Misc queries) 2 February 11th 09 12:33 AM
How to do the coding on UNTIL loop? Eric Excel Worksheet Functions 3 June 14th 07 03:31 PM
Inefficient? Steph[_3_] Excel Programming 3 April 19th 05 08:48 PM
Loop worked but is it inefficient? Bob Phillips[_5_] Excel Programming 2 August 13th 03 12:10 AM
Loop worked but is it inefficient? steve Excel Programming 2 August 12th 03 09:16 PM


All times are GMT +1. The time now is 08:57 PM.

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

About Us

"It's about Microsoft Excel"