Results 1 to 3 of 3

Thread: [RESOLVED] [Excel VBA] Open popup form by clicking on a cell

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    7

    Resolved [RESOLVED] [Excel VBA] Open popup form by clicking on a cell

    Hello everyone! I found this function that allows to open a popup window by clicking on a particular cell:
    Code:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
        If Target.Address = "$A$3" Then
            Cancel = True
            MsgBox "Here is your code!"
        End If
    End Sub
    What I want to do is integrate this function in my code: in practice, the following Sub conducts a search for a word on a range of cells and, if found, make the cell red. It should also enable the opening of a form (newarticle) in the VBAProject.
    Code:
    Sub CheckRecords()
    ...
    	With Sheets(1).Range("B6:B100")
    		'search the word in the stringa variable in the range B6:B100
    		Set Rng = .Find(What:=stringa, _
    				After:=.Cells(.Cells.Count), _
    				LookIn:=xlFormulas, _
    				LookAt:=xlWhole, _
    				SearchOrder:=xlByRows, _
    				SearchDirection:=xlNext, _
    				MatchCase:=False)
    			'If it find the word colors of red cell and enables opening form
    			If Not Rng Is Nothing Then
    				Rng.Interior.ColorIndex = 3
    				'Rng.Address returns the absolute address of the cell (ex: $B$9)
    				???how to enable form???
    			End If
    	End With
    ...
    End Sub
    My question is: how to enable the opening of the form (newarticle) by clicking on the cells marked by the search?
    I hope I have clearly explained the problem ... and thanks in advance to all!

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Excel VBA] Open popup form by clicking on a cell

    ???how to enable form???
    userform1.show
    change name of userform to suit, userform must be in same workbook as code
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2011
    Posts
    7

    Re: [Excel VBA] Open popup form by clicking on a cell

    [SOLVED] Put this code outside the Sub... Thanks!

    Code:
    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
      If Target.Interior.ColorIndex = 3 Then
        Cancel = True
        newarticle.Show
      End If
    End Sub

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width