vbYesNo to populate cell

Phoenix333

New Member
Joined
Sep 28, 2010
Messages
26
HI! I have a weird thing happening and i'm hoping someone can help fix it.

When I select a specific worksheet, I want the macro to look at B8 and if it's empty, ask me the msg box.

The code I have does this, but when I select yes, it populates the cell with a 6, not Yes and when I select No, it populates the cell with a 7, instead of No.

Here's the code I'm using

Code:
Sub Worksheet_Activate()
    Dim Adhoc As String
        If Range("B8").Value > 0 Then Exit Sub Else
        
        Adhoc = MsgBox("Is this an Adhoc project?", vbYesNo, Adhoc)
        Range("B8").Value = Adhoc

End Sub

The only things I'm finding when I search this online are vbYesNo to call macro, end macro, pop a message box, but nothing that populates a cell with the Yes or No answer.

I have tried adding code that says
If Adhoc = Yes then Range("B8").value = Yes...etc etc, but that doesn't work either.

Any ideas where i'm messing this up?

Thanks!
T-
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
vbYes is a constant that is equal to 6. Try this
Code:
Sub Worksheet_Activate()
    Dim Adhoc As Long
        If Range("B8").Value > 0 Then Exit Sub Else
        
        Adhoc = MsgBox("Is this an Adhoc project?", vbYesNo, vbNullString)
        Range("B8").Value = "No"
        If Adhoc = vbYes Then
            Range("B8").Value = "Yes"
        End If

End Sub
 
Upvote 0
YES!!! I'm so excited! Awesome! Thank you so much! Fabulous!

This was perfect, it does exactly what I need. Thank you thank you thank you!
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,559
Members
449,089
Latest member
Motoracer88

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
Back
Top