ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Code Question (https://www.excelbanter.com/excel-programming/425005-vbulletin-code-question.html)

Stan

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!

Gary''s Student

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!


Stan

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!


Gord Dibben

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!



Stan

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!




Gord Dibben

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!






All times are GMT +1. The time now is 10:04 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com