View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JS2004R6 JS2004R6 is offline
external usenet poster
 
Posts: 22
Default lookup formatted cell

Hi Kim,

Here is some code that might work for you. It will look to see if each Cell
in range A1:A10000 has an interior ColorIndex of 5 (BLUE). If it does then it
will set the value of that cell to "Yes", otherwise "No". Simply change the
name of the sheet "Sheet1" and the range "A1:A10000" to meet your needs.

Hope it helps.

Regards,
James

Sub SetYesNoValue()
'DECLARATIONS
'------------
Dim wks As Worksheet
Dim rng As Range

'INITIALIZE
'----------
On Error GoTo ErrHandler
' Change the name of "Sheet1" below to your worksheet name.
Set wks = ThisWorkbook.Worksheets("Sheet1")

'MAIN BODY
'---------
Application.ScreenUpdating = False
' Change the value of the range "A1:A10000" to your range.
For Each rng In wks.Range("A1:A10000")
If rng.Interior.ColorIndex = 5 Then ' ColorIndex 5 = BLUE
rng.Value = "Yes"
Else
rng.Value = "No"
End If
Next rng
Application.ScreenUpdating = True
MsgBox "DONE"

'WRAP-UP
'-------
GoSub CleanUp
Exit Sub

'CLEAN-UP
'--------
CleanUp:
Application.ScreenUpdating = True
Set wks = Nothing
Set rng = Nothing
Return

'ERROR HANDLER
'-------------
ErrHandler:
MsgBox "Error Number: " & Err.Number & vbCrLf & vbCrLf &
Err.Description, _
vbOKOnly + vbInformation, "SetYesNoValue()"
GoSub CleanUp
End Sub

"Kim" wrote:

I am trying to write a formula similar to vlookup. Basically, what I want
to do is write a formula or something that will look at a cell and if that
cell is highlighted blue, then the cell equals yes; if not then cell equals
no. This worksheet has over 10000 rows. Is this possible? I was looking
into writing a macro or something, but I don't know where to start.

Thanks
Kim