+ Reply to Thread
Results 1 to 9 of 9

After error message, return to original cell

  1. #1
    Registered User
    Join Date
    10-17-2021
    Location
    Langley, BC
    MS-Off Ver
    Office 365
    Posts
    23

    After error message, return to original cell

    hello,

    Enter date cell is H2. If user tries to select and enter info in other cells before entering value in H2 (date) I would like error message to occur (which it does) but have excel return to cell H2 (which it does not).

    Here is the code I have so far.

    Private Sub Worksheet_Change(ByVal Target As Range)

    'ENTER DATE
    If Range("H2") = "" Then
    MsgBox "Please enter DATE first.", vbCritical, "Error Data Entry"
    Exit Sub
    End If

    JR

  2. #2
    Registered User
    Join Date
    10-17-2021
    Location
    Langley, BC
    MS-Off Ver
    Office 365
    Posts
    23

    Re: After error message, return to original cell

    Also, I only want this to occur until DATE is entered into Cell H2. After DATE entered, user can move on to other cells in Workbook

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: After error message, return to original cell


    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-17-2021
    Location
    Langley, BC
    MS-Off Ver
    Office 365
    Posts
    23

    Re: After error message, return to original cell

    That works. Thank you.

    bug: When user enters anything but date (example - as) error message occurs "Run-Time Error '1004' Cannot change part of a merged cell"

    Johny

  5. #5
    Registered User
    Join Date
    10-17-2021
    Location
    Langley, BC
    MS-Off Ver
    Office 365
    Posts
    23

    Re: After error message, return to original cell

    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Intersect(Target, Range("H2")) Is Nothing Then
    If Range("H2") = "" Then
    Target.ClearContents
    Range("H2").Select
    MsgBox "Please enter DATE first.", vbCritical, "Error Data Entry"
    End If
    Else
    If Target.Value <> "" Then
    If Not IsDate(Target.Value) Then
    Target.ClearContents
    Target.Select
    MsgBox "Not a DATE", vbCritical, "Error Date Entry"
    End If
    End If
    End If
    Application.EnableEvents = True

    *** Target.ClearContents is displayed with Yellow Highlight over it

  6. #6
    Registered User
    Join Date
    10-17-2021
    Location
    Langley, BC
    MS-Off Ver
    Office 365
    Posts
    23

    Re: After error message, return to original cell

    appears cells H2 to L2 are merged. That is what is causing the issue. Maybe by substituting H2 with H2:L2?

    Johny

  7. #7
    Registered User
    Join Date
    10-17-2021
    Location
    Langley, BC
    MS-Off Ver
    Office 365
    Posts
    23

    Re: After error message, return to original cell

    thats ok. I just un-merged the cells. this is solved

  8. #8
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,301

    Re: After error message, return to original cell

    For merged cells try this:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-17-2021
    Location
    Langley, BC
    MS-Off Ver
    Office 365
    Posts
    23

    Re: After error message, return to original cell

    Hello, If I wanted to add, user must enter date AND "NAME" to this code whereas N2 (merged cells) is Name cell, how would I do that? Error message to user changes to "Please enter DATE and NAME first".

+ 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. [SOLVED] If cell is empty in a variable range, stop macro and return error message
    By Andrei Kononenko in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-22-2019, 02:19 PM
  2. How to return an error message
    By xcracer41 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-12-2018, 04:02 PM
  3. [SOLVED] VBA to return focus to original starting cell
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-17-2017, 12:24 PM
  4. Return to original page & cell after macro
    By aljanga in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-08-2015, 10:09 AM
  5. [SOLVED] Return carriage not returning to row under original cell
    By HH61 in forum Excel General
    Replies: 4
    Last Post: 05-07-2014, 02:08 PM
  6. Replies: 2
    Last Post: 09-25-2012, 01:48 PM
  7. Automatic entry and return to original cell.
    By process in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2011, 06:26 PM

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