+ Reply to Thread
Results 1 to 12 of 12

Userform opened by double click containing data from worksheet

  1. #1
    Registered User
    Join Date
    04-17-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    12

    Userform opened by double click containing data from worksheet

    Hi

    I have a userform which opens when a specific cell is double clicked on a worksheet. This userform has two textboxes which bring up information from another part of the worksheet. My code is below is written on the worksheet itself. The userform opens upon double clicking but the data retrieved by the userform is for the previous double click. For example the first time I double-click on C9 both boxes are blank. The next time I click on Cell C9 it correctly returns values in cells C109 and C209. If I then clicked on Cell D9, it would then return the values I would have expected for C9.

    Please can you advise if I am missing some code or if the with userform instructions are in the wrong place?

    Private Sub Worksheet_beforedoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("C8:CL100")) Is Nothing Then
    Marketinfo.Show
    With Marketinfo
    .txtAddinfo = Target.Offset(200, 0).Value
    .txtSSI = Target.Offset(100, 0).Value
    End With
    Cancel = True
    End If
    End Sub

    Thanks very much

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Userform opened by double click containing data from worksheet

    Try moving Cancel = True before the MarketInfo.Show.


    PS Can you add code tags? Makes the code easy on the eye and also easy to copy.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    04-17-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Userform opened by double click containing data from worksheet

    Hi Norie

    Thanks for your response, sorry about the coding issue, I will take note for future. I updated the code but it still has the same issue - do you have any other suggestions?

    Please Login or Register  to view this content.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Userform opened by double click containing data from worksheet

    I thought that might have made a difference.

    Not sure why I though it.

    Anyway, can you attach a sample workbook?

    PS Are you unloading, not hiding, the form between double clicks?

  5. #5
    Registered User
    Join Date
    04-17-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Userform opened by double click containing data from worksheet

    It's a work project so I am unable to upload as it contains sensitive info...sorry.

    I have a Close button on the userform which hides the form when clicked

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Userform opened by double click containing data from worksheet

    Try unloading the form instead of hiding in.

    Hiding a form means it's still loaded in memory.

  7. #7
    Registered User
    Join Date
    04-17-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Userform opened by double click containing data from worksheet

    I tried chaning the close button to "Unload Me" but that still does not fix the problem.

    Thanks for your continued suggestions though do you have any other theories?

  8. #8
    Registered User
    Join Date
    04-17-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Userform opened by double click containing data from worksheet

    Do I also need to change "Marketinfo.show" to something like "Load Market info"?

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Userform opened by double click containing data from worksheet

    Not really, without seeing the workbook anyway.

    I tried a little mock up but couldn't recreate the behaviour.

    Is there anything else happening code-wise?

    For example code in the Initalize (or Activate) event of the form?

    Could you create a stripped down verion of the workbook without any data and attach that?

  10. #10
    Registered User
    Join Date
    04-17-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Userform opened by double click containing data from worksheet

    Ok I've created a dummy of what I have. I have the same issue on the dummy workbook as I do on the original.

    Thanks!
    Attached Files Attached Files

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Userform opened by double click containing data from worksheet

    It isn't the Cancel=True you need to move, it's the .Show part.

    When that's executed control passes to the userform and until it's unloaded/hidden and only then do the textboxes get populated.

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-17-2013
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: Userform opened by double click containing data from worksheet

    Excellent that works! Thank you very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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