how do i change this code to be a userform not a messagebox?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,574
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi everyone,
I was advised that as I wanted to position the messagebox in the top right of the screen I should use a userform instead,
I've created the userform (just called userform1) with two boxes yes / no but I don't know how to get it to replace my message box?
can someone please help me? what code do I use to get the same results but with my userform instead of the message box?
the code is:

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim answer
answer = MsgBox("Is This a Good Site?", vbYesNo + vbQuestion, "Empty Sheet")
If answer = vbYes Then
ActiveCell.Offset(0, 1) = "Good site"
ActiveCell.Offset(0, 1).Select
answer = ""
End If
End Sub
the code is placed in sheet2 and activates when I doubleclick a website in a cell.
Thanks

Tony
 

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
try
Code:
userform1.show
The problem you're going to encounter however is that the form itself won't pass back a return value, so you're going to have to include the code shown as part of the userform code, rather than in the calling sub
 

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
2,574
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Weaver,
I'm normally ok with translating and sort these sort of thing out but I'm just getting totally lost, think i'll just stick to using it as it is! but thanks for your help.
Tony
 

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
Fine by me, but you're really not that far away. If your userform has buttons, you can attach code to them. If you can do this then all you need to do is to make a function in the form make your sheet changes.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,330
Messages
5,528,043
Members
409,799
Latest member
mlewan_ca

This Week's Hot Topics

Top