Code for checking "Error" & "#N/A" in specific columns and returning the columns with issue (if the case)

IosifFlorin

New Member
Joined
Jul 1, 2015
Messages
18
Hello everyone,

as the title mentions, i am trying to check for specific error words in column P -> R & T (starting with row 5 for all).
I was looking on the internet and i managed to bring together the below code.

- I am trying now to figure out how can i check all these columns and return text when for example only column Q and T have the error words ( so based on where the issue, to receive a message with the specific column/columns).
- if there is no error words, than at the end a message of "ok" suffices

Thanks for your help, let me know in case some additional information would be required.


Lastrow = ThisWorkbook.Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row With Sheets("Sheet1").Range("Q5:Q" & Lastrow)

Set check1 = .Find("#N/A", LookIn:=xlValues)
If check1 Is Nothing Then
MsgBox "Column Q ok"
Else
MsgBox ("Check Business Unit (Column Q)!!!")
End If
End With
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Try this:
Code:
Sub MyErrorCheck()

    Dim Lastrow As Long
    Dim Myrow As Long
    
    Lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    
    For Myrow = 5 To Lastrow
        If Application.WorksheetFunction.IsNA(Cells(Myrow, "Q")) Then
            MsgBox ("Check Business Unit (Column Q)!!!")
            Exit Sub
        End If
    Next Myrow
    
    MsgBox "Column Q ok"

End Sub
 
Upvote 0
thanks Joe for the code, unfortunately it's not solving what i wanted to implement:

- check cells in columns P -> R & T for specific words like "#N/A", "Error"
- return text with the columns where the specific words are found or "all is ok"
 
Upvote 0
Sorry, I misunderstood, and was focusing more on fixing up your code and missed some key details in your question.

I think this may do what you are looking for:
Code:
Sub MyErrorCheck()

    Dim Lastrow As Long
    Dim Myrow As Long
    Dim myColumns As Variant
    Dim i As Byte
    Dim myErrorMessage As String
    
'   Set array with columns to check
    myColumns = Array("P", "Q", "R", "T")
    
'   Use column A to find last row with data
    Lastrow = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
    
'   Loop through all columns in array
    For i = LBound(myColumns) To UBound(myColumns)
'       Loop through all rows
        For Myrow = 5 To Lastrow
            If Application.WorksheetFunction.IsError(Cells(Myrow, myColumns(i))) Then
'               Add error message to string
                myErrorMessage = myErrorMessage & "Check Business Unit (Column " & myColumns(i) & ")!!!" & vbCrLf
                Exit For
            End If
        Next Myrow
    Next i
    
'   Check to see if any errors
    If myErrorMessage = "" Then
        myErrorMessage = "All columns are OK!"
    End If
    
'   Return message box
    MsgBox myErrorMessage


End Sub
 
Last edited:
Upvote 0
thank you very much Joe, this is it :)
no need to apologize! thanks for your help

is it much more complex if i want to look for specific words? ( you can take whichever example of words as you wish, just want to understand the principle/way to do it)
 
Upvote 0
You would probably want to set up another array that holds your list of words, and loop through that for each cell, sort of like this here: http://www.mrexcel.com/forum/excel-...-using-find-list-words-not-just-one-word.html

If you do it that way, you can probably eliminate the need to loop through each cell/row, and just use the FIND functionality on an entire column at a time.

Note that if you are looking for "words", the words returned by errors may not work they way you think (i.e. the "#N/A" error that is returned is not the same thing as the text string "#N/A").
 
Upvote 0
thanks :)
i copy / paste values + use iferror and that's why i asked + for future cases when i actually have to look for specific words
 
Upvote 0

Forum statistics

Threads
1,215,013
Messages
6,122,690
Members
449,092
Latest member
snoom82

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