+ Reply to Thread
Results 1 to 3 of 3

How do I show a userform based on content of a cell?

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-05-2009
    Location
    South Dakota, USA
    MS-Off Ver
    365
    Posts
    152

    How do I show a userform based on content of a cell?

    What I am attempting to do is show a userform if A1 = 5.

    In another section of code, I made a few userforms come up if a certain cell was selected. I thought I could utilize the same code and just add to it allowing me to show a uf if the content of a certain cell = a predetermined number(s) or letter(s)

    This is the code that I tried to use but did not work.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        Select Case Target.Address
            Case "$A$80:$BI$80": ufMutualAid.Show
            Case "$A$83:$BI$84": ufPersonnel.Show
            Case "$A$87:$BI$87": ufApparatus.Show
            Case "$A$90:$BI$90": ufExtricationTools.Show
            Case "A1=5": ufMutual Aid.Show
            Case Else:    'do nothing in other cells
        End Select
    End Sub
    Do I need a different sub or can I just change something in this one to make it work? I also tried
    Case "A1"=5: ufMutualAid.show
    and it also did not work.

    Thanks in advance for any help.

  2. #2
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: How do I show a userform based on content of a cell?

    hello,
    try this in the case statement.
            Case "$A$1"
            If Target.Value = 5 Then ufMutualAid.show


  3. #3
    Forum Contributor
    Join Date
    01-05-2009
    Location
    South Dakota, USA
    MS-Off Ver
    365
    Posts
    152

    Re: How do I show a userform based on content of a cell?

    Okay,

    Here is what I have come up with. I tried the previous code without success and so I modified it to do what I thought would work but I keep coming up with different errors and the current one is type mismatch. I believe that is because I am asking "case a value" and then putting in a string, but I am not sure if that is why and if it is what I need to do to fix it. Here is my code. The part in red is the only part that I am changing, the rest works as needed.
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
        Select Case Target.Address
            Case "$A$80:$BI$80": ufMutualAid.Show
            Case "$A$83:$BI$84": ufPersonnel.Show
            Case "$A$87:$BI$87": ufApparatus.Show
            Case "$A$90:$BI$90": ufExtricationTools.Show
            Case Else:    'do nothing in other cells
        End Select
            
        Select Case Target.Value
            Case "$CallInitialView"
                If Target.Value = "MV-" Then
                ufApparatus.Show
        
        If Not Application.Intersect(Target, Me.Range("A24")) Is Nothing Then
            Application.Goto Sheets(1).Range("A24"), True
             Range("K26:AF26").Select
       Else
          If Not Application.Intersect(Target, Me.Range("A45")) Is Nothing Then
                  Application.Goto Sheets(1).Range("A45"), True
                   Range("H48:R48").Select
       Else
          If Not Application.Intersect(Target, Me.Range("A71")) Is Nothing Then
                  Application.Goto Sheets(1).Range("A71"), True
                   Range("J73:BI73").Select
       Else
          If Not Application.Intersect(Target, Me.Range("A76")) Is Nothing Then
                  Application.Goto Sheets(1).Range("A76"), True
                   Range("N77:AB77").Select
       Else
          If Not Application.Intersect(Target, Me.Range("A92")) Is Nothing Then
                  Application.Goto Sheets(1).Range("A92"), True
                   Range("A94:BI100").Select
          End If
          End If
          End If
          End If
        Exit Sub
    End If
    End If
    End Select
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1