#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Case Select

Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in ColZ. However
if Z is blank the code stops. If Z is blank I would like the cell to be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Case Select

Hi, try this:

For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case "": ColorCell cell, 0
Case Else: ColorCell cell, -4142
End Select
Next

HTH--Lonnie M.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Case Select

Case "": ColorCell cell, xlColorIndexNone

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Bill" wrote in message
...
Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in ColZ. However
if Z is blank the code stops. If Z is blank I would like the cell to be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Case Select

Bill,

Doesn't stop for me. I had yellow cells in V5, W5, and X5 and Z5 was empty,
and it cleared them nicely.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in ColZ. However
if Z is blank the code stops. If Z is blank I would like the cell to be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Case Select

Brain cramp!!!!!---The cells were negative! How would I modify Case for
"CAT" and negative.
Thanks!

"Bob Phillips" wrote:

Bill,

Doesn't stop for me. I had yellow cells in V5, W5, and X5 and Z5 was empty,
and it cleared them nicely.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in ColZ. However
if Z is blank the code stops. If Z is blank I would like the cell to be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Case Select

Which part? The case else handles negatives.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Brain cramp!!!!!---The cells were negative! How would I modify Case for
"CAT" and negative.
Thanks!

"Bob Phillips" wrote:

Bill,

Doesn't stop for me. I had yellow cells in V5, W5, and X5 and Z5 was

empty,
and it cleared them nicely.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in ColZ.

However
if Z is blank the code stops. If Z is blank I would like the cell to

be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Case Select

Where do you get codes for the colours?

"Bob Phillips" wrote in message
...
Which part? The case else handles negatives.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Brain cramp!!!!!---The cells were negative! How would I modify Case for
"CAT" and negative.
Thanks!

"Bob Phillips" wrote:

Bill,

Doesn't stop for me. I had yellow cells in V5, W5, and X5 and Z5 was

empty,
and it cleared them nicely.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in ColZ.

However
if Z is blank the code stops. If Z is blank I would like the cell

to
be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill








  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 691
Default Case Select

see http://www.mvps.org/dmcritchie/excel/colors.htm
in a pinch you can look in VBE Help for colorindex
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm

"Himszy" wrote in message ...
Where do you get codes for the colours?



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 390
Default Case Select

Values for "CAT" and be positive, negative. In this case I only want to
shade the negative cells. In a manner of speaking adding an AND to the case
statement. Cell =CAT and < 0 is shaded.
Thanks!
"Bob Phillips" wrote:

Which part? The case else handles negatives.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Brain cramp!!!!!---The cells were negative! How would I modify Case for
"CAT" and negative.
Thanks!

"Bob Phillips" wrote:

Bill,

Doesn't stop for me. I had yellow cells in V5, W5, and X5 and Z5 was

empty,
and it cleared them nicely.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in ColZ.

However
if Z is blank the code stops. If Z is blank I would like the cell to

be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill







  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Case Select

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell Case(cell.Value),cell, 39
Case "dog": ColorCell Case(cell.Value),cell, 35
Case "fish": ColorCell Case(cell.Value),cell, 34
Case "horse": ColorCell Case(cell.Value),cell, 36
Case Else: ColorCell Case(cell.Value),cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(val As string, rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If (val = "cat" And c < 0) Or _
c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Values for "CAT" and be positive, negative. In this case I only want to
shade the negative cells. In a manner of speaking adding an AND to the

case
statement. Cell =CAT and < 0 is shaded.
Thanks!
"Bob Phillips" wrote:

Which part? The case else handles negatives.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Brain cramp!!!!!---The cells were negative! How would I modify Case

for
"CAT" and negative.
Thanks!

"Bob Phillips" wrote:

Bill,

Doesn't stop for me. I had yellow cells in V5, W5, and X5 and Z5 was

empty,
and it cleared them nicely.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in ColZ.

However
if Z is blank the code stops. If Z is blank I would like the cell

to
be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill











  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Case Select

Typo, that should be

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell LCase(cell.Value),cell, 39
Case "dog": ColorCell LCase(cell.Value),cell, 35
Case "fish": ColorCell LCase(cell.Value),cell, 34
Case "horse": ColorCell LCase(cell.Value),cell, 36
Case Else: ColorCell LCase(cell.Value),cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bob Phillips" wrote in message
...
Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell Case(cell.Value),cell, 39
Case "dog": ColorCell Case(cell.Value),cell, 35
Case "fish": ColorCell Case(cell.Value),cell, 34
Case "horse": ColorCell Case(cell.Value),cell, 36
Case Else: ColorCell Case(cell.Value),cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(val As string, rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If (val = "cat" And c < 0) Or _
c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function



--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Values for "CAT" and be positive, negative. In this case I only want to
shade the negative cells. In a manner of speaking adding an AND to the

case
statement. Cell =CAT and < 0 is shaded.
Thanks!
"Bob Phillips" wrote:

Which part? The case else handles negatives.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Brain cramp!!!!!---The cells were negative! How would I modify Case

for
"CAT" and negative.
Thanks!

"Bob Phillips" wrote:

Bill,

Doesn't stop for me. I had yellow cells in V5, W5, and X5 and Z5

was
empty,
and it cleared them nicely.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bill" wrote in message
...
Hi
Im new to VB and I am trying to modify some one else's code.
The code colors the cells according to the cell contents in

ColZ.
However
if Z is blank the code stops. If Z is blank I would like the

cell
to
be
clear. How do I add the case for blank?

Private Sub Commandbutton1_Click()
Dim cell As Range
On Error GoTo ws_exit:
Application.EnableEvents = False
For Each cell In Me.Range("z5:z36")
Select Case LCase(cell.Value)
Case "cat": ColorCell cell, 39
Case "dog": ColorCell cell, 35
Case "fish": ColorCell cell, 34
Case "horse": ColorCell cell, 36
Case Else: ColorCell cell, -4142

End Select
Next
ws_exit:
Application.EnableEvents = True
End Sub

Function ColorCell(rng As Range, idex As Long)
Dim c As Range
With rng
For Each c In .Offset(0, -24).Resize(1, 24)

If c < "" Then
If IsNumeric(c) Then
If c 0 Then c.Interior.ColorIndex = idex
End If
End If
Next
End With
End Function


Thanks
Bill











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
Select Case ignored Preschool Mike Excel Worksheet Functions 4 September 9th 09 08:12 PM
Case Select NoodNutt Excel Worksheet Functions 7 September 21st 08 02:10 AM
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
Need help on Select Case Susan Hayes Excel Worksheet Functions 1 November 3rd 04 10:25 PM
select case help please Christine Flott[_2_] Excel Programming 4 July 29th 03 09:05 PM


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