+ Reply to Thread
Results 1 to 3 of 3

Creating a MsgBox for a required data field

  1. #1
    Registered User
    Join Date
    07-15-2014
    Location
    New York, New York
    MS-Off Ver
    2010
    Posts
    7

    Creating a MsgBox for a required data field

    Hi, I am trying to write a macro in VBA that displays a message box if a user enters a number in a field, but fails to enter a description in the column to the left of it. Here is the code I have so far:

    Sub MsgBox()

    Dim r As Range
    Dim Buttons As String

    Buttons = vbOKOnly + vbExclamation

    For Each r In Range("E6:E16")

    If r.Value = "" Then
    Exit Sub

    ElseIf r.Value <> "" Then
    If r.Offset(0, -1).Value <> "" Then
    Exit Sub
    ElseIf r.Offset(0, -1).Value = "" Then
    VBA.MsgBox "Please fill in the details section to continue.", Buttons, "Entry Required"
    End If
    End If
    Next r

    End Sub

    And here is a snippet of what the document looks like:

    VBA example.PNG

    Basically what I am trying to say here is if there is NO value in the BLUE cell then exit the macro because it is irrelevant, however, if there is a value in the BLUE cell and if there is a value in the cell to the left (YELLOW), then also exit the sub. BUT, if there is a value in the BLUE cell and there is NO value in the cell to the left (YELLOW), then MsgBox should appear that tells the user to enter a value in the YELLOW cell. The goal is to get users to provide some detail for the number they input and not just the number itself. This is for a budget.

    If anyone could help it would be greatly appreciated!

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Creating a MsgBox for a required data field

    Hi and welcome to the forum. Unfortunately your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-15-2014
    Location
    New York, New York
    MS-Off Ver
    2010
    Posts
    7

    Re: Creating a MsgBox for a required data field

    Very Sorry about that! I am new to the Forum. Does this work?


    Hi, I am trying to write a macro in VBA that displays a message box if a user enters a number in a field, but fails to enter a description in the column to the left of it. Here is the code I have so far:

    Please Login or Register  to view this content.
    And here is a snippet of what the document looks like:

    VBA example.PNG

    Basically what I am trying to say here is if there is NO value in the BLUE cell then exit the macro because it is irrelevant, however, if there is a value in the BLUE cell and if there is a value in the cell to the left (YELLOW), then also exit the sub. BUT, if there is a value in the BLUE cell and there is NO value in the cell to the left (YELLOW), then MsgBox should appear that tells the user to enter a value in the YELLOW cell. The goal is to get users to provide some detail for the number they input and not just the number itself. This is for a budget.

    If anyone could help it would be greatly appreciated!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 12-11-2013, 02:55 AM
  2. [SOLVED] Issue in creating the right formula to give the data required
    By amasson in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 01-29-2013, 08:57 AM
  3. Check each row, if each proceeding row matches, take data and put in required field t
    By mattsmithnl in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-08-2011, 03:27 PM
  4. Replies: 0
    Last Post: 07-10-2010, 03:02 PM
  5. Creating an overdue date field to update data automatically
    By simjambra in forum Access Tables & Databases
    Replies: 1
    Last Post: 03-05-2009, 12:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1