Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default How to fill a column with color in statement

I want to make a code that check in a range of cells if the number entered by
the user is greater that 0, turn that cell in red and send a message to the
user. I tried this code but not work for me.

Dim rng As Range

Set rng = Range("$B$5:$B$11")

If rng 0 Then
MessageBox.Show ("You have an Alert!")
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 340
Default How to fill a column with color in statement

In the worksheet's code sheet (access by right clicking on the tab and
selecting view code), you can put code like the following:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim anyR As Range
Dim cell As Range
On Error Resume Next
Set anyR = Intersect(Target, Range("$B$5:$B$11"))
On Error GoTo 0
If anyR Is Nothing Then Exit Sub
For Each cell In anyR
If cell.Value 0 Then
MsgBox "Cell " & cell.Address & " value is 0)"
End If
Next
End Sub

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


"anamarie30" wrote in message
...
I want to make a code that check in a range of cells if the number entered
by
the user is greater that 0, turn that cell in red and send a message to
the
user. I tried this code but not work for me.

Dim rng As Range

Set rng = Range("$B$5:$B$11")

If rng 0 Then
MessageBox.Show ("You have an Alert!")
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 340
Default How to fill a column with color in statement

woops. Forgot to color the cell. The following does that :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim anyR As Range
Dim cell As Range
On Error Resume Next
Set anyR = Intersect(Target, Range("$B$5:$B$11"))
On Error GoTo 0
If anyR Is Nothing Then Exit Sub
For Each cell In anyR
If cell.Value 0 Then
MsgBox "Cell " & cell.Address & " value is 0)"
cell.Interior.ColorIndex = 3
End If
Next
End Sub

Bob

"anamarie30" wrote in message
...
I want to make a code that check in a range of cells if the number entered
by
the user is greater that 0, turn that cell in red and send a message to
the
user. I tried this code but not work for me.

Dim rng As Range

Set rng = Range("$B$5:$B$11")

If rng 0 Then
MessageBox.Show ("You have an Alert!")
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default How to fill a column with color in statement

Thanks Bob. It work great!

"Bob Flanagan" wrote:

woops. Forgot to color the cell. The following does that :

Private Sub Worksheet_Change(ByVal Target As Range)
Dim anyR As Range
Dim cell As Range
On Error Resume Next
Set anyR = Intersect(Target, Range("$B$5:$B$11"))
On Error GoTo 0
If anyR Is Nothing Then Exit Sub
For Each cell In anyR
If cell.Value 0 Then
MsgBox "Cell " & cell.Address & " value is 0)"
cell.Interior.ColorIndex = 3
End If
Next
End Sub

Bob

"anamarie30" wrote in message
...
I want to make a code that check in a range of cells if the number entered
by
the user is greater that 0, turn that cell in red and send a message to
the
user. I tried this code but not work for me.

Dim rng As Range

Set rng = Range("$B$5:$B$11")

If rng 0 Then
MessageBox.Show ("You have an Alert!")
With Selection.Interior
.ColorIndex = 3
.Pattern = xlSolid
End With
End If

End Sub




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
Fill Color If Statement Elgee Excel Worksheet Functions 3 August 5th 08 10:13 PM
How do you Control the fill color using an if statement formula? RussCrowder Excel Worksheet Functions 2 June 1st 07 09:31 PM
Changing cell fill color as result of 'if' statement jason Excel Programming 0 August 31st 03 04:51 PM
Changing cell fill color as result of 'if' statement Tom Ogilvy Excel Programming 0 August 31st 03 04:25 PM
Changing cell fill color as result of 'if' statement Phobos Excel Programming 0 August 31st 03 12:41 PM


All times are GMT +1. The time now is 05:37 PM.

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

About Us

"It's about Microsoft Excel"