Adding to code for pop-ups

ChristineJ

Well-known Member
Joined
May 18, 2009
Messages
761
Office Version
  1. 365
Platform
  1. Windows
This code below from my worksheet creates a pop-up box when certain cells in columns Q, S, and U have a value and are selected. The contents of the pop-up include the text values in other cells in the same row. (Blue text below.)

I'd like to ADD similar functionality for creating the pop-ups in certain cells in columns BI, BK, BM, and BO. However, rather than pulling the text values in the pop-ups from cells in the same row, I would like any cell in a column to have the same contents in the pop-up.

For example, when any cell in the range in BI is clicked on, its pop-up would have:
This is test 1.
This is test 2.
This is test 3.
ANSWER: 55

When any cell in the range in BK is selected, the pop-up would have:
This is test 4.
This is test 5.
This is test 6.
ANSWER: 77

Same for the other two columns. The text sentences would vary quite a bit more than my example above.
Can this code be modified? Thanks.


Rich (BB code):
    Dim strTitle As String
    Dim strMsg As String
    Dim lDVType As Long
    Dim sTemp As Shape
    On Error Resume Next
    Set sTemp = ActiveSheet.Shapes("txtInputMsg")
    '*
    'Code will only work if A13=1 (pop-ups) A34=1 so pop-up does not appear before grading occurs (next line)
    If Range("B6").Value <> 1 Then Exit Sub
    If Range("A34").Value <> 1 Then Exit Sub
    
    '* Add the box if does not exist
    If Err.Number <> 0 Then
        Set sTemp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 10, 10, 72, 72)
        sTemp.Name = "txtInputMsg"
    End If
    '*
    '* Exit if not in range
    
    With Target
        ' test whether there is more than one cell in the selection, that the cell is in
        ' column 'Q', 'S', or 'U' (Each of these is a named range), that there is something in the cell
        ' and that it has a validation rule applied.
        lDVType = 99
        lDVType = Target.Validation.Type
        If 1 < .Cells.Count Or _
                Application.Intersect(.Cells, Union(Range("ColumnQ"), Range("ColumnS"), Range("ColumnU"))) Is Nothing Or _
                .Value = "" Or lDVType = 99 Then
        
            sTemp.TextFrame.Characters.Text = ""
            sTemp.Visible = msoFalse
        Else
            Application.EnableEvents = False
            .Validation.ShowInput = False
            Select Case .Column
                'Each of these is the column number
                Case 17    '* Column Q
                    strTitle = IIf(CStr(Range("AO" & .Row)) = "", "", (CStr(Range("AO" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AP" & .Row)) = "", "", (CStr(Range("AP" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AQ" & .Row)) = "", "", (CStr(Range("AQ" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AG" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                        CStr(Range("AG" & .Row)))
                Case 19    '* Column S
                    strTitle = IIf(CStr(Range("AR" & .Row)) = "", "", (CStr(Range("AR" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AS" & .Row)) = "", "", (CStr(Range("AS" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AT" & .Row)) = "", "", (CStr(Range("AT" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AI" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                        CStr(Format(Range("AI" & .Row), "#,###")))
    
                Case 21    '* Column U
                    strTitle = IIf(CStr(Range("AU" & .Row)) = "", "", (CStr(Range("AU" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AV" & .Row)) = "", "", (CStr(Range("AV" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AW" & .Row)) = "", "", (CStr(Range("AW" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AK" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                    CStr(Format(Range("AK" & .Row), "#,###")))
    
            End Select
            strMsg = IIf(Range("B1") = 3, "", strMsg)
            strTitle = IIf(Range("B1") = 2, "", strTitle)
            '*
            '* Remove last vbCR from strTitle if strMsg = ""
            strTitle = IIf(strMsg = "", LEFT(strTitle, Len(strTitle) - 1), strTitle)
            sTemp.TextFrame.Characters.Text = strTitle & strMsg
            sTemp.TextFrame.AutoSize = True
            sTemp.TextFrame.Characters.Font.Bold = False
            sTemp.TextFrame.Characters(1, Len(strTitle)).Font.Bold = False
            sTemp.LEFT = .Offset(0, -5).LEFT
            sTemp.Top = .Top - sTemp.Height
            sTemp.Visible = msoTrue
        
            On Error GoTo 0
            Application.EnableEvents = True
        End If
    End With
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
This should be what it should look like.

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)    Dim strTitle As String
    Dim strMsg As String
    Dim lDVType As Long
    Dim sTemp As Shape


    '*
    'Code will only work if B6=1 (pop-ups) A34=1 so pop-up does not appear before grading occurs (next line)
    If Range("B6").Value <> 1 Then Exit Sub
    If Range("A34").Value <> 1 Then Exit Sub


    On Error Resume Next
    Set sTemp = ActiveSheet.Shapes("txtInputMsg")
    On Error GoTo 0


    With Target
        ' test whether there is more than one cell in the selection, that the cell is in
        ' column 'Q', 'S', or 'U' (Each of these is a named range), that there is something in the cell
        ' and that it has a validation rule applied.
        lDVType = 99
    On Error Resume Next
        If Target.Validation.Type Then lDVType = Target.Validation.Type
    On Error GoTo 0
        If 1 < .Cells.Count Then Exit Sub
        
        If Application.Intersect(.Cells, Union(Range("ColumnQ"), Range("ColumnS"), Range("ColumnU"), _
                Range("ColumnBI"), Range("ColumnBM"), Range("ColumnBK"), Range("ColumnBO"))) Is Nothing Or _
                .Value = "" Or lDVType = 99 Then
            If Not sTemp Is Nothing Then    'if txtbox does exist
                sTemp.TextFrame.Characters.Text = ""
                sTemp.Visible = msoFalse
            End If


            Exit Sub
        Else
            Application.EnableEvents = False
            .Validation.ShowInput = False
            '* Add the box if does not exist
            If sTemp Is Nothing Then
                Set sTemp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 10, 10, 72, 72)
                sTemp.Name = "txtInputMsg"
            End If
            '*
            Select Case .Column
                'Each of these is the column number
                Case 17    '* Column Q
                    strTitle = IIf(CStr(Range("AO" & .Row)) = "", " ", (CStr(Range("AO" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AP" & .Row)) = "", "", (CStr(Range("AP" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AQ" & .Row)) = "", "", (CStr(Range("AQ" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AG" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                        CStr(Range("AG" & .Row)))
                Case 19    '* Column S
                    strTitle = IIf(CStr(Range("AR" & .Row)) = "", " ", (CStr(Range("AR" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AS" & .Row)) = "", "", (CStr(Range("AS" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AT" & .Row)) = "", "", (CStr(Range("AT" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AI" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                        CStr(Format(Range("AI" & .Row), "#,###")))


                Case 21    '* Column U
                    strTitle = IIf(CStr(Range("AU" & .Row)) = "", " ", (CStr(Range("AU" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AV" & .Row)) = "", "", (CStr(Range("AV" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AW" & .Row)) = "", "", (CStr(Range("AW" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AK" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                    CStr(Format(Range("AK" & .Row), "#,###")))
                
                Case Range("ColumnBI").Column
                    strTitle = "ColumnBI"
                    strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                Case Range("ColumnBK").Column
                    strTitle = "ColumnBK"
                    strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                Case Range("ColumnBM").Column
                    strTitle = "ColumnBM"
                    strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                Case Range("ColumnBO").Column
                    strTitle = "ColumnBO"
                    strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"


            End Select
            strMsg = IIf(Range("B1") = 3, "", strMsg)
            strTitle = IIf(Range("B1") = 2, "", strTitle)
            '*
            '* Remove last vbCR from strTitle if strMsg = ""
            strTitle = IIf(strMsg = "", Left(strTitle, Len(strTitle) - 1), strTitle)
            sTemp.TextFrame.Characters.Text = strTitle & strMsg
            sTemp.TextFrame.AutoSize = True
            sTemp.TextFrame.Characters.Font.Bold = False
            sTemp.TextFrame.Characters(1, Len(strTitle)).Font.Bold = False
            sTemp.Left = .Offset(0, -5).Left
            sTemp.Top = .Top - sTemp.Height
            sTemp.Visible = msoTrue


            Application.EnableEvents = True
        End If
    End With
End Sub

I have also cleaned up some stuff in your code.
You trapped errors at the very start (On Error Next) and released that at the end.

But this masked (or could mask) a whole lot of other errors. Not good practice.

Now I have only used it around the check to see if the message box exists, and if the target has validation set.

Also the message box gets created first time only when it is will be used.

The errors that were hidden by encapsulating everything with On error Next were:
If the msgTitle was blank then the IIF function to delete the last vbCr was throwing an error. To solve this I added a space to the msgTitle
If the cell did not have validation set.

Note that I have assumed you are using rangenames again for the columns to be checked

Chek out how I am using this in the Select statement. Where you have Case 21 for column U, I use
Code:
Case Range("ColumnBI").Column
This means that if at some future date columns are inserted or deleted the code still works

Hope this helps.
 
Upvote 0
Thanks so much for your help. Your code worked the way I needed it to, and I was able to clean up what I had as you suggested. I am very new at working with this code.

If you don't mind, I have one other question. You see I have

If Range("B6").Value <> 1 Then Exit Sub
If Range("A34").Value <> 1 Then Exit Sub


in the code. I don't need the If Range("A34").Value <> 1 Then Exit Sub at all now, so I removed that.

What if I wanted this:

If Range("B6").Value <> 1 Then Exit Sub for Case Range("ColumnQ").Column, Case Range("ColumnS").Column, and Case Range("ColumnU").Column only
If Range("B7").Value <> 1 Then Exit Sub for Case Range("ColumnBI").Column
If Range("B8").Value <> 1 Then Exit Sub for Case Range("ColumnBK").Column
If Range("B9").Value <> 1 Then Exit Sub for Case Range("ColumnBM").Column
If Range("B10").Value <> 1 Then Exit Sub for Case Range("ColumnBO").Column

The code would stop running based on different rows in column B for different cases.

Thanks again!
 
Upvote 0
You need to add these checks within the Case for each column. So for the first Case (Column Q) you would have
Code:
                Case Range("ColumnQ").column    '* Column Q
		    If Range("B6").Value <> 1 Then Exit Sub


                    strTitle = IIf(CStr(Range("AO" & .Row)) = "", " ", (CStr(Range("AO" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AP" & .Row)) = "", "", (CStr(Range("AP" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AQ" & .Row)) = "", "", (CStr(Range("AQ" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AG" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                        CStr(Range("AG" & .Row)))

But now your empty textbox would show. So we want to move the textbox creation/make visible to after the End Select statement:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim strTitle As String
    Dim strMsg As String
    Dim lDVType As Long
    Dim sTemp As Shape




    '*
    'Code will only work if B6=1 (pop-ups) A34=1 so pop-up does not appear before grading occurs (next line)
    If Range("B6").Value <> 1 Then Exit Sub
 '   If Range("A34").Value <> 1 Then Exit Sub




    On Error Resume Next
    Set sTemp = ActiveSheet.Shapes("txtInputMsg")
    On Error GoTo 0




    With Target
        ' test whether there is more than one cell in the selection, that the cell is in
        ' column 'Q', 'S', or 'U' (Each of these is a named range), that there is something in the cell
        ' and that it has a validation rule applied.
        lDVType = 99
    On Error Resume Next
        If Target.Validation.Type Then lDVType = Target.Validation.Type
    On Error GoTo 0
        If 1 < .Cells.Count Then Exit Sub
        
        If Application.Intersect(.Cells, Union(Range("ColumnQ"), Range("ColumnS"), Range("ColumnU"), _
                Range("ColumnBI"), Range("ColumnBM"), Range("ColumnBK"), Range("ColumnBO"))) Is Nothing Or _
                .Value = "" Or lDVType = 99 Then
            If Not sTemp Is Nothing Then    'if txtbox does exist
                sTemp.TextFrame.Characters.Text = ""
                sTemp.Visible = msoFalse
            End If




            Exit Sub
        Else
            Application.EnableEvents = False
            .Validation.ShowInput = False
            '*
            Select Case .Column
                'Each of these is the column number
                Case Range("ColumnQ").Column    '* Column Q
                    If Range("B6").Value <> 1 Then Exit Sub
                    strTitle = IIf(CStr(Range("AO" & .Row)) = "", " ", (CStr(Range("AO" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AP" & .Row)) = "", "", (CStr(Range("AP" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AQ" & .Row)) = "", "", (CStr(Range("AQ" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AG" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                        CStr(Range("AG" & .Row)))
                Case Range("ColumnS").Column    '* Column S
                    If Range("B6").Value <> 1 Then Exit Sub
                    strTitle = IIf(CStr(Range("AR" & .Row)) = "", " ", (CStr(Range("AR" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AS" & .Row)) = "", "", (CStr(Range("AS" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AT" & .Row)) = "", "", (CStr(Range("AT" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AI" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                        CStr(Format(Range("AI" & .Row), "#,###")))




                Case Range("ColumnU").Column    '* Column U
                    If Range("B6").Value <> 1 Then Exit Sub
                    strTitle = IIf(CStr(Range("AU" & .Row)) = "", " ", (CStr(Range("AU" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AV" & .Row)) = "", "", (CStr(Range("AV" & .Row)) & vbCr)) & _
                        IIf(CStr(Range("AW" & .Row)) = "", "", (CStr(Range("AW" & .Row)) & vbCr))
                    strMsg = IIf(CStr(Range("AK" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                    CStr(Format(Range("AK" & .Row), "#,###")))
                
                Case Range("ColumnBI").Column
                    If Range("B7").Value <> 1 Then Exit Sub
                    strTitle = "ColumnBI"
                    strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                Case Range("ColumnBK").Column
                    If Range("B8").Value <> 1 Then Exit Sub
                    strTitle = "ColumnBK"
                    strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                Case Range("ColumnBM").Column
                    If Range("B9").Value <> 1 Then Exit Sub
                    strTitle = "ColumnBM"
                    strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                Case Range("ColumnBO").Column
                    If Range("B10").Value <> 1 Then Exit Sub
                    strTitle = "ColumnBO"
                    strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"




            End Select
            strMsg = IIf(Range("B1") = 3, "", strMsg)
            strTitle = IIf(Range("B1") = 2, "", strTitle)
            '*
            '* Remove last vbCR from strTitle if strMsg = ""
            strTitle = IIf(strMsg = "", Left(strTitle, Len(strTitle) - 1), strTitle)
            '* Add the box if does not exist
            If sTemp Is Nothing Then
                Set sTemp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 10, 10, 72, 72)
                sTemp.Name = "txtInputMsg"
            End If
            sTemp.TextFrame.Characters.Text = strTitle & strMsg
            sTemp.TextFrame.AutoSize = True
            sTemp.TextFrame.Characters.Font.Bold = False
            sTemp.TextFrame.Characters(1, Len(strTitle)).Font.Bold = False
            sTemp.Left = .Offset(0, -5).Left
            sTemp.Top = .Top - sTemp.Height
            sTemp.Visible = msoTrue




            Application.EnableEvents = True
        End If
    End With
End Sub

However by using exit sub, the cleanup of the macro is skipped (in this case events are still disabled. So it would be better if we don't exit the sub, but just exit the select. To do that we need to add a flag. We set the flag true when we want to show the textbox.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim strTitle As String
    Dim strMsg As String
    Dim lDVType As Long
    Dim sTemp As Shape
    Dim bFlag As Boolean




    '*
    'Code will only work if B6=1 (pop-ups) A34=1 so pop-up does not appear before grading occurs (next line)
    If Range("B6").Value <> 1 Then Exit Sub
 '   safe to exit sub here as we haven't changed anything yet


    bFlag = False


    On Error Resume Next
    Set sTemp = ActiveSheet.Shapes("txtInputMsg")
    On Error GoTo 0




    With Target
        ' test whether there is more than one cell in the selection, that the cell is in
        ' column 'Q', 'S', or 'U' (Each of these is a named range), that there is something in the cell
        ' and that it has a validation rule applied.
        lDVType = 99
    On Error Resume Next
        If Target.Validation.Type Then lDVType = Target.Validation.Type
    On Error GoTo 0
        If 1 < .Cells.Count Then Exit Sub
        
        If Application.Intersect(.Cells, Union(Range("ColumnQ"), Range("ColumnS"), Range("ColumnU"), _
                Range("ColumnBI"), Range("ColumnBM"), Range("ColumnBK"), Range("ColumnBO"))) Is Nothing Or _
                .Value = "" Or lDVType = 99 Then
            If Not sTemp Is Nothing Then    'if txtbox does exist
                sTemp.TextFrame.Characters.Text = ""
                sTemp.Visible = msoFalse
            End If




            Exit Sub
        Else
            Application.EnableEvents = False
            .Validation.ShowInput = False
            '*
            Select Case .Column
                'Each of these is the column number
                Case Range("ColumnQ").Column    '* Column Q
                    If Range("B6").Value = 1 Then
                        bFlag = True
                        strTitle = IIf(CStr(Range("AO" & .Row)) = "", " ", (CStr(Range("AO" & .Row)) & vbCr)) & _
                            IIf(CStr(Range("AP" & .Row)) = "", "", (CStr(Range("AP" & .Row)) & vbCr)) & _
                            IIf(CStr(Range("AQ" & .Row)) = "", "", (CStr(Range("AQ" & .Row)) & vbCr))
                        strMsg = IIf(CStr(Range("AG" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                            CStr(Range("AG" & .Row)))
                    End If
                Case Range("ColumnS").Column    '* Column S
                    If Range("B6").Value = 1 Then
                        bFlag = True
                        strTitle = IIf(CStr(Range("AR" & .Row)) = "", " ", (CStr(Range("AR" & .Row)) & vbCr)) & _
                            IIf(CStr(Range("AS" & .Row)) = "", "", (CStr(Range("AS" & .Row)) & vbCr)) & _
                            IIf(CStr(Range("AT" & .Row)) = "", "", (CStr(Range("AT" & .Row)) & vbCr))
                        strMsg = IIf(CStr(Range("AI" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                            CStr(Format(Range("AI" & .Row), "#,###")))
                    End If




                Case Range("ColumnU").Column    '* Column U
                    If Range("B6").Value = 1 Then
                        bFlag = True
                        strTitle = IIf(CStr(Range("AU" & .Row)) = "", " ", (CStr(Range("AU" & .Row)) & vbCr)) & _
                            IIf(CStr(Range("AV" & .Row)) = "", "", (CStr(Range("AV" & .Row)) & vbCr)) & _
                            IIf(CStr(Range("AW" & .Row)) = "", "", (CStr(Range("AW" & .Row)) & vbCr))
                        strMsg = IIf(CStr(Range("AK" & .Row)) = "", "ANSWER:   Leave blank", "ANSWER:   " & _
                        CStr(Format(Range("AK" & .Row), "#,###")))
                    End If
                
                Case Range("ColumnBI").Column
                    If Range("B7").Value = 1 Then
                        bFlag = True
                        strTitle = "ColumnBI"
                        strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                    End If
                Case Range("ColumnBK").Column
                    If Range("B8").Value = 1 Then
                        bFlag = True
                        strTitle = "ColumnBK"
                        strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                    End If
                Case Range("ColumnBM").Column
                    If Range("B9").Value = 1 Then
                        bFlag = True
                        strTitle = "ColumnBM"
                        strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                    End If
                Case Range("ColumnBO").Column
                    If Range("B10").Value = 1 Then
                        bFlag = True
                        strTitle = "ColumnBO"
                        strMsg = "This is test 1." & vbCr & "This is test 2." & vbCr & "This is test 3." & vbCr & "ANSWER: 55"
                    End If




            End Select
            If bFlag Then
                strMsg = IIf(Range("B1") = 3, "", strMsg)
                strTitle = IIf(Range("B1") = 2, "", strTitle)
                '*
                '* Remove last vbCR from strTitle if strMsg = ""
                strTitle = IIf(strMsg = "", Left(strTitle, Len(strTitle) - 1), strTitle)
                '* Add the box if does not exist
                If sTemp Is Nothing Then
                    Set sTemp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 10, 10, 72, 72)
                    sTemp.Name = "txtInputMsg"
                End If
                sTemp.TextFrame.Characters.Text = strTitle & strMsg
                sTemp.TextFrame.AutoSize = True
                sTemp.TextFrame.Characters.Font.Bold = False
                sTemp.TextFrame.Characters(1, Len(strTitle)).Font.Bold = False
                sTemp.Left = .Offset(0, -5).Left
                sTemp.Top = .Top - sTemp.Height
                sTemp.Visible = msoTrue
            End If


            Application.EnableEvents = True
        End If
    End With
End Sub
 
Upvote 0
Excellent - thank you so much. I will test this out in a little while and let you know how it goes. I appreciate your explanations as well - I am learning so much. CJ
 
Upvote 0
It is giving me an error Method 'Range' of Object' Worksheet' Failed

It highlights this part, and a small arrow points to the last line:

If Application.Intersect(.Cells, Union(Range("ColumnQ"), Range("ColumnS"), Range("ColumnU"), _
Range("ColumnBI"), Range("ColumnBM"), Range("ColumnBK"), Range("ColumnBO"))) Is Nothing Or _
.Value = "" Or lDVType = 99 Then


Columns Q, S, and U include different rows than BI, BM, BK and BO, Could that be an issue?
 
Upvote 0
No as long as these range names exist the code doesn't give a monkeys.
Make sure that your range names for the columns are the same as the range names in this piece of code, else change the code to suit.
 
Upvote 0
You were right; one of my range names was incorrect. The resolved the error it was giving.

However, the pop-ups are not appearing when I click on a cell in the range that has a value. B6:B10 all have values of 1.
 
Upvote 0
Does the cell that you click on also have a validation? Your code checks to see if validation is in place, else it exits.
Code:
    On Error Resume Next
        If Target.Validation.Type Then lDVType = Target.Validation.Type
    On Error GoTo 0


...


    If Application.Intersect(.C...) ... Or lDVType = 99 Then
 
Upvote 0
Yes, all of the cells in the named ranges have validation. I double checked that. Under the Data Validation Input Message box, I have a word in both the Title and Input Message boxes. Then I deselected "Show input message when cell is selected." That worked for the code I originally posted.
 
Upvote 0

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top