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

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,034
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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

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
3,034
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.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,302
Messages
5,836,512
Members
430,436
Latest member
fefenouil

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
Top