Share via

simple error message if text box is empty

Anonymous
2015-04-03T09:52:58+00:00

I have a userform which I can calculate the VAT of a certain item.

I have a Net Textbox, VAT text box, a current %VAT textbox and a calculate command button.

On calculation the code I am using is

txtVat = txtNet / 100 * Percentage

I have added 

If Percentage = "" Then

MsgBox "Enter the VAT% you wish to use to calculate with"

End If

To appear of there is not VAT% inserted in the %VAT textbox. This works fine for the error message, but when I click OK on the msgbox I get Debug

what am I missing from my code.

Thanks

Steve

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

HansV 462.6K Reputation points
2015-04-03T10:06:01+00:00

You could exit the calculation:

    If Me.Percentage = "" Then

        MsgBox "Enter the VAT% you wish to use to calculate with"

        Me.Percentage.SetFocus

        Exit Sub

    End If

Was this answer helpful?

0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Anonymous
    2015-04-03T11:02:37+00:00

    Cheers Hans

    I had actually tried your code, but in a different way, hence it not working. this is great thanks

    Steve

    Was this answer helpful?

    0 comments No comments