+ Reply to Thread
Results 1 to 3 of 3

Prevent macros running after message box show

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-11-2009
    Location
    Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    252

    Prevent macros running after message box show

    I just got a code from stnkynts
    Sub RunMe()
    Dim icell As Integer
    
    For icell = 1 To 4
        If Range("A" & icell).Value = "" And Range("B" & icell).Value <> "" Then
            MsgBox ("There is an error in Row " & icell)
        ElseIf Range("B" & icell).Value = "" And Range("A" & icell).Value <> "" Then
            MsgBox ("There is an error in Row " & icell)
        End If
    Next icell
    
    End Sub
    And when I combine with my other code like:
    Sub RunMe()
    Dim icell As Integer
    
    For icell = 1 To 4
        If Range("A" & icell).Value = "" And Range("B" & icell).Value <> "" Then
            MsgBox ("There is an error in Row " & icell)
        ElseIf Range("B" & icell).Value = "" And Range("A" & icell).Value <> "" Then
            MsgBox ("There is an error in Row " & icell)
        End If
    Next icell
    
    Range("A1:B1").Value = vbNullString
    End Sub
    Every time message box appears and click OK ... the value in the cell erased
    if the many data is entered it will be hard to type it again
    Is there any code to prevent the value in the cell is not deleted before editing

    Thanks in advance

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Prevent macros running after message box show

    Hi, herukuncahyono,

    tell VBA to exit the sub?

    Sub RunMe()
    Dim icell As Integer
    
    For icell = 1 To 4
        If Range("A" & icell).Value = "" And Range("B" & icell).Value <> "" Then
            MsgBox ("There is an error in Row " & icell)
            Exit Sub
        ElseIf Range("B" & icell).Value = "" And Range("A" & icell).Value <> "" Then
            MsgBox ("There is an error in Row " & icell)
            Exit Sub
        End If
    Next icell
    
    Range("A1:B1").Value = vbNullString
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    03-11-2009
    Location
    Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    252

    Re: Prevent macros running after message box show

    hi Holger

    Wow.. its work...
    Thank you so much..

    for stnkynts thank you too

+ 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. Prevent two macros from running at the same time
    By Kreef in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-31-2011, 10:36 PM
  2. Prevent the Enable macros message
    By buckau in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-27-2009, 04:14 PM
  3. Prevent functions from running while macro is running
    By palpha32 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-24-2009, 08:42 PM
  4. Macro message yet no macros running....
    By Steve-B in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-10-2008, 09:36 AM
  5. [SOLVED] Prevent others from running my macros
    By Frederick Chow in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-13-2005, 02:10 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