ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting the color for each cell in a selection (https://www.excelbanter.com/excel-programming/359857-getting-color-each-cell-selection.html)

Brian J. Matuschak

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


Die_Another_Day

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



Gary''s Student

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


Tom Ogilvy

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



All times are GMT +1. The time now is 01:31 PM.

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