Msgbox to pop up only once considering multiple errors in column

jharih1

New Member
Joined
Dec 5, 2017
Messages
14
Good afternoon,

I looked through multiple posts on the forum boards, but something is not working properly with my code. I was hoping some of you VB experts can help me.

What I wish for it to do = look up errors in a column, highlight the erroneous cells red, and popup a msgbox once saying "Please enter valid month".

I created a public sub function to do the lookups..I think the code will speak to itself:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)


'Checks if vlookup function returns an "ERROR" for all data validation and vendor number fields.
'If it is blank or has valid data, no conditional formatting will be used.
'If checks = "Error" then cell should be highlighted and a msgbox will popup requesting user to enter valid info.


Check_Month
End Sub
Code:
Public Sub Check_Month()
Dim Warning As Boolean


For i = 2 To 9999


    If Cells(i, 22).Value = "ERROR" Then
       Cells(i, 1).Interior.Color = RGB(198, 30, 2)
       MsgBox "Please enter valid Month"
       Warning = True
    Else:
       Cells(i, 1).Interior.ColorIndex = 0
       Warning = False
    End If
    
Next i


End Sub

Please help! I hate VB now :(
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
So this morning, I had one of my coworkers download the spreadsheet from sharepoint and test on her computer. We keep getting a 1004 VB Error, and the debug is pointing at
Code:
Public Sub Check_Month()
Dim Warning As Boolean


Warning = False


For i = 2 To 9999


    If Cells(i, 22).Value = "ERROR" Then
[COLOR=#ff0000]       Cells(i, 1).Interior.Color = RGB(198, 30, 2)[/COLOR]
       Warning = True
    Else:
[COLOR=#ff0000]       Cells(i, 1).Interior.ColorIndex = 0[/COLOR]
    End If


Next i


If Warning Then
    MsgBox "Please enter valid Month"
End If


End Sub

Any suggestions why? It was working Friday when the spreadsheet was housed on my local machine, but after posting to Sharepoint - there are a few bugs. 1) if I copy paste info in any field, it automatically locks that particular cell (when it originally is set to unlocked), and errors out on this info. I wished to protect the spreadsheet.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,315
Members
452,634
Latest member
cpostell

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