Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pop up message needed dependend on certain conditions
In cell range C7:C14 the cells can have different values (1, 2, 3, .....)
In case there is only 1 kind of value (only value 1, or only value 2) I'd like to get a message (pop up, or in a certain cell), which says "blablabla" I'd like to get different messages for different values, though. For example: C7 = 1 C8 = 1 C9 = 1 Message to pop up: "Please be aware that pattern repeat to be divisible by 4" C7 = 2 C8 = 2 C9 = 2 C10 = 2 Message to pop up: "Please be aware that pattern repeat to be divisible by 12" For example: C7 = 1 C8 = 2 C9 = 1 No message to pop up |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pop up message needed dependend on certain conditions
Norbert wrote:
In cell range C7:C14 the cells can have different values (1, 2, 3, .....) In case there is only 1 kind of value (only value 1, or only value 2) I'd like to get a message (pop up, or in a certain cell), which says "blablabla" I'd like to get different messages for different values, though. For example: C7 = 1 C8 = 1 C9 = 1 Message to pop up: "Please be aware that pattern repeat to be divisible by 4" C7 = 2 C8 = 2 C9 = 2 C10 = 2 Message to pop up: "Please be aware that pattern repeat to be divisible by 12" For example: C7 = 1 C8 = 2 C9 = 1 No message to pop up This ensures that there are at least 2 unique values in C7:C14, and at least 2 non-blank cells. If there aren't (i.e. everything's the same) then you get a msgbox. Private Sub Worksheet_Change(ByVal Target As Range) Dim L0, L1, tracker As Boolean If (Target.Column < 3) Or (Target.Row < 7) Or (Target.Row 14) Then _ Exit Sub For L0 = 7 To 13 If Cells(L0, 3).Value < "" Then For L1 = 8 To 14 If Cells(L1, 3).Value < "" Then tracker = True If Cells(L0, 3).Value < Cells(L1, 3).Value Then Exit Sub End If Next End If Next If tracker Then MsgBox "your message here" End Sub -- I wonder if he thinks he's the hero or the villain? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pop up message needed dependend on certain conditions
On Monday, 26 March 2018 17:24:59 UTC+2, Auric__ wrote:
Norbert wrote: In cell range C7:C14 the cells can have different values (1, 2, 3, .....) In case there is only 1 kind of value (only value 1, or only value 2) I'd like to get a message (pop up, or in a certain cell), which says "blablabla" I'd like to get different messages for different values, though. For example: C7 = 1 C8 = 1 C9 = 1 Message to pop up: "Please be aware that pattern repeat to be divisible by 4" C7 = 2 C8 = 2 C9 = 2 C10 = 2 Message to pop up: "Please be aware that pattern repeat to be divisible by 12" For example: C7 = 1 C8 = 2 C9 = 1 No message to pop up This ensures that there are at least 2 unique values in C7:C14, and at least 2 non-blank cells. If there aren't (i.e. everything's the same) then you get a msgbox. Private Sub Worksheet_Change(ByVal Target As Range) Dim L0, L1, tracker As Boolean If (Target.Column < 3) Or (Target.Row < 7) Or (Target.Row 14) Then _ Exit Sub For L0 = 7 To 13 If Cells(L0, 3).Value < "" Then For L1 = 8 To 14 If Cells(L1, 3).Value < "" Then tracker = True If Cells(L0, 3).Value < Cells(L1, 3).Value Then Exit Sub End If Next End If Next If tracker Then MsgBox "your message here" End Sub -- I wonder if he thinks he's the hero or the villain? Hello Auric, first of all thank you for your help! At first, I had no clue what you did and had to play with the code a little to understand. I tried to change it to do the following: - as soon as I have made the 4th entry (into cell C10) I want the code to check whether there is all ones, twos, threes, ...... - in case there is all ones I want the message to be: "Please ensure the pick repeat to be divisible by 4" - in case there is all twos, I want the message to be: "Please ensure the pick repeat to be divisible by 12" that is all for now! (I think I can extend it myself if I have code for above requirements) That's how far I got: Private Sub Worksheet_Change(ByVal Target As Range) Dim L0, L1, tracker1 As Boolean If (Target.Column < 3) Or (Target.Row < 7) Or (Target.Row 14) Then _ Exit Sub For L0 = 7 To 13 If Cells(L0, 3).Value = 1 Then For L1 = 10 To 14 If Cells(L1, 3).Value = 1 Then tracker1 = True If Cells(L0, 3).Value < Cells(L1, 3).Value Then Exit Sub End If Next End If Next Dim L2, L3, tracker2 As Boolean If (Target.Column < 3) Or (Target.Row < 7) Or (Target.Row 14) Then _ Exit Sub For L2 = 7 To 13 If Cells(L2, 3).Value = 2 Then For L3 = 10 To 14 If Cells(L3, 3).Value = 2 Then tracker2 = True If Cells(L2, 3).Value < Cells(L3, 3).Value Then Exit Sub End If Next End If Next If tracker1 Then MsgBox "Please ensure that the pick repeat is divisible by 4 (for Reppe)" If tracker2 Then MsgBox "Please ensure that the pick repeat is divisible by 12 (for Satin)" End Sub It works for when it is all ones or when it is all twos, but it also comes up with a message, when it is mixed (ones and twos). |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pop up message needed dependend on certain conditions
Norbert wrote:
On Monday, 26 March 2018 17:24:59 UTC+2, Auric__ wrote: Norbert wrote: In cell range C7:C14 the cells can have different values (1, 2, 3, .....) In case there is only 1 kind of value (only value 1, or only value 2) I'd like to get a message (pop up, or in a certain cell), which says "blablabla" I'd like to get different messages for different values, though. For example: C7 = 1 C8 = 1 C9 = 1 Message to pop up: "Please be aware that pattern repeat to be divisible by 4" C7 = 2 C8 = 2 C9 = 2 C10 = 2 Message to pop up: "Please be aware that pattern repeat to be divisible by 12" For example: C7 = 1 C8 = 2 C9 = 1 No message to pop up This ensures that there are at least 2 unique values in C7:C14, and at least 2 non-blank cells. If there aren't (i.e. everything's the same) then you get a msgbox. [snip] Hello Auric, first of all thank you for your help! At first, I had no clue what you did and had to play with the code a little to understand. I tried to change it to do the following: - as soon as I have made the 4th entry (into cell C10) I want the code to check whether there is all ones, twos, threes, ...... - in case there is all ones I want the message to be: "Please ensure the pick repeat to be divisible by 4" - in case there is all twos, I want the message to be: "Please ensure the pick repeat to be divisible by 12" that is all for now! (I think I can extend it myself if I have code for above requirements) That's how far I got: [snip] It works for when it is all ones or when it is all twos, but it also comes up with a message, when it is mixed (ones and twos). Try this. It won't pop the msgbox up unless there are at least 4 entered values. I've also commented everything so you can see each line's purpose. Note that as-is, it will bitch about *any* series of identical non-blank values, whether it's 1, 2, a, $, whatever. To avoid that, delete the Case Else at the end. Private Sub Worksheet_Change(ByVal Target As Range) Dim L0, L1, checkVal, tracker As Long 'If Target (the changed range) is outside C7:C14, exit. If (Target.Column < 3) Or (Target.Row < 7) Or (Target.Row 14) Then _ Exit Sub 'Check for blank C7 and set tracker appropriately. '(to avoid off-by-one error). If Range("C7").Value < "" Then tracker = 1 'For each cell in C7:C13... For L0 = 7 To 13 '...ensure it's not blank, then... If Cells(L0, 3).Value < "" Then '...stuff the value into a var for later use, then... checkVal = Cells(L0, 3).Value '...compare against all cells below it.... For L1 = 8 To 14 '...also ensuring each one is not blank. If Cells(L1, 3).Value < "" Then 'This is set to check for multiple non-blank cells, 'for later use. tracker = tracker + 1 'Non-unique values; exit the sub with no further action. If Cells(L0, 3).Value < Cells(L1, 3).Value Then Exit Sub End If Next End If Next 'If we get here, then: '- there are multiple non-blank cells, and '- every cell in C7:C13 has the same value. 'The value we check tracker against (3 in this example) 'might need to be adjusted to suit your needs. If tracker 3 Then Select Case checkVal Case 1 MsgBox "Please ensure the pick repeat to be divisible by 4" Case 2 MsgBox "Please ensure the pick repeat to be divisible by 12" Case 3 MsgBox "You mentioned 'all threes'..." Case Else MsgBox "All identical values but not a listed option" End Select End If End Sub -- peanut butter is my spiritual guide |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Pop up message needed dependend on certain conditions
Great! I am happy with the way it works. And thank you very much for your comments in between, that helps me a lot to better understand the code.
The Case Else is helpful as well. Best regards! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
help needed to add values with conditions | Excel Worksheet Functions | |||
Formula Needed : Sum on Conditions | Excel Discussion (Misc queries) | |||
Formula Needed : Sum on Conditions | Excel Programming | |||
Date Formula with 2 conditions met needed | Excel Discussion (Misc queries) | |||
Two conditions in one cell. Help needed ASAP | Excel Discussion (Misc queries) |