Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Getting the color for each cell in a selection

OK, so I pressed the wrong key before my message was complete, but I'll
reiterate what I was trying to do. I need to check the color of each cell
within a one-row selection so that if the scheduler picks the wrong
selection, then they do not receive an Outlook appointment. I need to use a
command button to provide flexibility. Here's part of the sub:

Dim rng As Range

For Each rng in Selection
If rng.Interior.ColorIndex < 4 Then
MsgBox "You did not select the correct cells for scheduling",
vbCritical, "Improper Selection"
End If
Exit Sub
Next

What am I missing here?

Thanks,
--
Brian J. Matuschak

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Getting the color for each cell in a selection

I think you just put the exit sub in the wrong place (outside the if
statement)

Die_Another_Day

For Each rng in Selection
If rng.Interior.ColorIndex < 4 Then
MsgBox "You did not select the correct cells for scheduling",

vbCritical, "Improper Selection"
Exit Sub
End If
Next


Brian J. Matuschak wrote:
OK, so I pressed the wrong key before my message was complete, but I'll
reiterate what I was trying to do. I need to check the color of each cell
within a one-row selection so that if the scheduler picks the wrong
selection, then they do not receive an Outlook appointment. I need to use a
command button to provide flexibility. Here's part of the sub:

Dim rng As Range

For Each rng in Selection
If rng.Interior.ColorIndex < 4 Then
MsgBox "You did not select the correct cells for scheduling",
vbCritical, "Improper Selection"
End If
Exit Sub
Next

What am I missing here?

Thanks,
--
Brian J. Matuschak


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Getting the color for each cell in a selection

An easy fix:

Your Exit sub is inside the For Loop. You are only going thru the loop
once, not for every cell in Selection.


Move the Exit inside the IF
--
Gary's Student


"Brian J. Matuschak" wrote:

OK, so I pressed the wrong key before my message was complete, but I'll
reiterate what I was trying to do. I need to check the color of each cell
within a one-row selection so that if the scheduler picks the wrong
selection, then they do not receive an Outlook appointment. I need to use a
command button to provide flexibility. Here's part of the sub:

Dim rng As Range

For Each rng in Selection
If rng.Interior.ColorIndex < 4 Then
MsgBox "You did not select the correct cells for scheduling",
vbCritical, "Improper Selection"
End If
Exit Sub
Next

What am I missing here?

Thanks,
--
Brian J. Matuschak

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Getting the color for each cell in a selection

Exit sub should be within the IF statement right after the msgbox

--
Regards,
Tom Ogilvy


"Brian J. Matuschak" wrote:

OK, so I pressed the wrong key before my message was complete, but I'll
reiterate what I was trying to do. I need to check the color of each cell
within a one-row selection so that if the scheduler picks the wrong
selection, then they do not receive an Outlook appointment. I need to use a
command button to provide flexibility. Here's part of the sub:

Dim rng As Range

For Each rng in Selection
If rng.Interior.ColorIndex < 4 Then
MsgBox "You did not select the correct cells for scheduling",
vbCritical, "Improper Selection"
End If
Exit Sub
Next

What am I missing here?

Thanks,
--
Brian J. Matuschak

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
Changing the color of Cell Selection? ks Excel Discussion (Misc queries) 2 December 18th 09 08:24 PM
Cell Range Selection Color WCMOUSER Excel Discussion (Misc queries) 1 October 18th 08 04:51 PM
How do I change the color for cell selection in excel? dminliberty New Users to Excel 8 March 19th 08 02:42 PM
Change Cell background color by selection Bob Wall Excel Worksheet Functions 1 August 27th 06 02:13 AM
Getting color of each cell in selection Brian J. Matuschak Excel Programming 3 April 26th 06 07:59 PM


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