Pop up showing the cell

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Good morning.

I have to prevent manual errors in a data entry operation: more precisely, if the user types a space " " in a cell in the range F11:F13, a pop up has to specify in which cell, to make easier the consequent correction.

This is my attempt: the error is located in the highlighted row.

Code:
Sub space()

Dim cell As Range
For Each cell In Range("F11:F13")
If InStr(1, cell, " ", 1) Then [B]MsgBox ("In the cell" & Range("F11:F13").Value & " you have typed a space")[/B]
Next

End Sub

Thank's in advance.
 
Last edited:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this:-
Code:
Dim cell As Range
For Each cell In Range("F11:F13")
If InStr(1, cell, " ", 1) Then MsgBox ("In cell address " & cell.Address & " you have typed a space")
Next
 
Upvote 0
Try this:-
Code:
Dim cell As Range
For Each cell In Range("F11:F13")
If InStr(1, cell, " ", 1) Then MsgBox ("In cell address " & cell.Address & " you have typed a space")
Next

Thank you. In line with your suggestion, I've tried to go forward checking a range (value 0: yes or not?).
If no, go on.
If yes, ask to user if go on or correction is needed.

Code:
Sub Test_zero()

Dim cell As Range, answer as boolean

For Each cell In Range("L11:L13")
    If cell.value = 0 Then
        answer=MsgBox (cell.address & " is Zero: Do you want to go on?", vbYesNo)
		if answer=vbNo then exit sub
        else
    End If
Next

End Sub

The problem is: answering no to the pop up, the test is not interrupted.
 
Last edited:
Upvote 0
Perhaps something like this:-
NB:- Instead of going to "MoreCode:" you could call a sub, to run some more code.
Code:
[COLOR="Navy"]Sub[/COLOR] MG06Dec18
[COLOR="Navy"]Dim[/COLOR] cell [COLOR="Navy"]As[/COLOR] Range, fd [COLOR="Navy"]As[/COLOR] Boolean, answer [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] cell [COLOR="Navy"]In[/COLOR] Range("L11:L13")
    [COLOR="Navy"]If[/COLOR] cell.Value = "0" [COLOR="Navy"]Then[/COLOR] fd = True: [COLOR="Navy"]Exit[/COLOR] For
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]If[/COLOR] fd [COLOR="Navy"]Then[/COLOR]
        answer = MsgBox(cell.Address & " is Zero do you want to go on", vbCritical + vbYesNo + vbQuestion)
            [COLOR="Navy"]If[/COLOR] answer = vbYes [COLOR="Navy"]Then[/COLOR]
                GoTo Morecode
            [COLOR="Navy"]ElseIf[/COLOR] answer = vbNo [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
            [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Else[/COLOR]
Morecode: MsgBox "Run more code here"
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Last edited:
Upvote 0
Perhaps something like this:-
NB:- Instead of going to "MoreCode:" you could call a sub, to run some more code.
Code:
[COLOR="Navy"]Sub[/COLOR] MG06Dec18
[COLOR="Navy"]Dim[/COLOR] cell [COLOR="Navy"]As[/COLOR] Range, fd [COLOR="Navy"]As[/COLOR] Boolean, answer [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] cell [COLOR="Navy"]In[/COLOR] Range("L11:L13")
    [COLOR="Navy"]If[/COLOR] cell.Value = "0" [COLOR="Navy"]Then[/COLOR] fd = True: [COLOR="Navy"]Exit[/COLOR] For
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]If[/COLOR] fd [COLOR="Navy"]Then[/COLOR]
        answer = MsgBox(cell.Address & " is Zero do you want to go on", vbCritical + vbYesNo + vbQuestion)
            [COLOR="Navy"]If[/COLOR] answer = vbYes [COLOR="Navy"]Then[/COLOR]
                GoTo Morecode
            [COLOR="Navy"]ElseIf[/COLOR] answer = vbNo [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
            [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Else[/COLOR]
Morecode: MsgBox "Run more code here"
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]If[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick

Thank's.

I'm trying to modify it, because if more then one value is zero, the pop up appears just once.

Nelson.
 
Upvote 0
Try this:-
The code loops through each cell in specified range and runs to "More code" if no "0" is found, else
Msgbox appears for Instruction whether to proceed or not.
Code:
[COLOR="Navy"]Sub[/COLOR] MG07Dec40
[COLOR="Navy"]Dim[/COLOR] cell [COLOR="Navy"]As[/COLOR] Range, answer [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] cell [COLOR="Navy"]In[/COLOR] Range("L11:L13")
    [COLOR="Navy"]If[/COLOR] cell.Value = "0" [COLOR="Navy"]Then[/COLOR]
        answer = MsgBox(cell.Address & " is Zero do you want to go on", vbCritical + vbYesNo + vbQuestion)
            [COLOR="Navy"]If[/COLOR] answer = vbYes [COLOR="Navy"]Then[/COLOR]
                GoTo Morecode
            [COLOR="Navy"]ElseIf[/COLOR] answer = vbNo [COLOR="Navy"]Then[/COLOR]
                [COLOR="Navy"]Exit[/COLOR] [COLOR="Navy"]Sub[/COLOR]
            [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Else[/COLOR]
Morecode: MsgBox "Run more code here"
    [COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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