Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default VB Code Question

Can someone help me by telling me how I can refer to a cell's color and the
perform an action? In other words, if a cell is red, then docmd.xxxxx?

Many thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default VB Code Question

Sub dural()
If ActiveCell.Interior.ColorIndex = 3 Then
MsgBox ("the active cell is red")
Else
MsgBox ("the active cell is not red")
End If
End Sub

--
Gary''s Student - gsnu200836


"Stan" wrote:

Can someone help me by telling me how I can refer to a cell's color and the
perform an action? In other words, if a cell is red, then docmd.xxxxx?

Many thanks!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default VB Code Question

Many thanks for the quick reply.

When I copy the code into Visual Basic then color code a cell, I don't
recieve the MsgBox so I must be doing something wrong. Do you have to refer
to the particular workbook or worksheet in the code?

"Gary''s Student" wrote:

Sub dural()
If ActiveCell.Interior.ColorIndex = 3 Then
MsgBox ("the active cell is red")
Else
MsgBox ("the active cell is not red")
End If
End Sub

--
Gary''s Student - gsnu200836


"Stan" wrote:

Can someone help me by telling me how I can refer to a cell's color and the
perform an action? In other words, if a cell is red, then docmd.xxxxx?

Many thanks!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default VB Code Question

Sub do_something()
If ActiveCell.Interior.ColorIndex = 3 Then
MsgBox "What now?" 'run a macro or do something
Else
MsgBox "Not Red!" 'do nothing and exit
End If
End Sub


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 12:57:01 -0800, Stan
wrote:

Can someone help me by telling me how I can refer to a cell's color and the
perform an action? In other words, if a cell is red, then docmd.xxxxx?

Many thanks!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 150
Default VB Code Question

Works Great! Do you know how I can tell what the ColorIndex is for each color?

I see that 3 = Red but I also need Green, Blue, Orange, and Yellow.

"Gord Dibben" wrote:

Sub do_something()
If ActiveCell.Interior.ColorIndex = 3 Then
MsgBox "What now?" 'run a macro or do something
Else
MsgBox "Not Red!" 'do nothing and exit
End If
End Sub


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 12:57:01 -0800, Stan
wrote:

Can someone help me by telling me how I can refer to a cell's color and the
perform an action? In other words, if a cell is red, then docmd.xxxxx?

Many thanks!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default VB Code Question

Run this macro.

Sub ListColorIndexes()
Dim Ndx As Long
Sheets.Add
For Ndx = 1 To 56
Cells(Ndx, 1).Interior.ColorIndex = Ndx
Cells(Ndx, 2).Value = Hex(ThisWorkbook.Colors(Ndx))
Cells(Ndx, 3).Value = Ndx
Next Ndx
End Sub


Gord

On Tue, 3 Mar 2009 13:56:30 -0800, Stan
wrote:

Works Great! Do you know how I can tell what the ColorIndex is for each color?

I see that 3 = Red but I also need Green, Blue, Orange, and Yellow.

"Gord Dibben" wrote:

Sub do_something()
If ActiveCell.Interior.ColorIndex = 3 Then
MsgBox "What now?" 'run a macro or do something
Else
MsgBox "Not Red!" 'do nothing and exit
End If
End Sub


Gord Dibben MS Excel MVP

On Tue, 3 Mar 2009 12:57:01 -0800, Stan
wrote:

Can someone help me by telling me how I can refer to a cell's color and the
perform an action? In other words, if a cell is red, then docmd.xxxxx?

Many thanks!




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
VBA code question peyman Excel Discussion (Misc queries) 5 February 5th 09 12:04 AM
vb code question Stan Excel Programming 0 April 28th 08 06:49 PM
vb code question Stan Excel Discussion (Misc queries) 8 April 25th 08 10:43 PM
vb code question Stan Excel Discussion (Misc queries) 1 April 25th 08 09:45 PM


All times are GMT +1. The time now is 07:14 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"