Can't get a macro to run if a criteria is met.

owen4512

Board Regular
Joined
Dec 10, 2014
Messages
71
Here's the Vb Code I used but I keep getting a "Argument Not Optional" message box.

I want for the macro to run if the value equals to "Iawn I Bwcio". But if the value equals to "Dyddiad Anghywir"
then I want a message box to appear and say ;
"Mae yna dyddiad anghywir wedi ei fewnbynnu! Mae angen newid hyn er mwyn cario ymlaen!"
Code:
Private Sub mewbynnuDataSioe(ByVal target As Range)
    If (Range(D5) = "Iawn I Bwcio") Then
    '
    ' Mewnbynnu_Data_Sioe Macro
    '
    ' Keyboard Shortcut: Ctrl+Shift+Q
    '
    Range("E3").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("E4").Select
        ElseIf (Range(D5) = "Dyddiad Anghywir") Then
        MsgBox "Mae yna dyddiad anghywir wedi ei fewnbynnu! Mae angen newid hyn er mwyn cario ymlaen!"
        
    End With
    End If
    Exit Sub
End Sub
Thanks in advanced, Owen.
 
Last edited by a moderator:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,221,418
Messages
6,159,790
Members
451,589
Latest member
Harold14

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