Code to test value in Cell

erock24

Well-known Member
Joined
Oct 26, 2006
Messages
1,163
I was hoping for code that will test cells e3:g3 in sheet 1 of workbook "AR" for a value of "OK" or "Error". These cells contain if formulas that return "OK" or "Error"
If all Cells = "OK" then I need the macro to put "Ok" in D5 in sheet 1 of workbook "Guide". If 1 or more cells = "Error" then put "Error" in D5.
Also, I know I could use a formula in D5, but I really need the code for my specific application.

Thank you very much for your time and help.
 

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,)
Code:
Sub Error_check()
Dim X As String
Dim Y As String
Application.ScreenUpdating = False
Guide = ActiveWorkbook.Name
Y = Dir("C:\Documents and Settings\j.doe\Desktop\AR.xls")
Workbooks.Open ("C:\Documents and Settings\j.doe\Desktop\AR.xls")
 If Range("E3") = "OK" Then
     If Range("F3") = "OK" Then
       If Range("G3") = "OK" Then
          X = "OK"
          Else: X = "Error"
        End If
       Else: X = "Error"
     End If
    Else: X = "Error"
  End If
Windows(Guide).Activate
Sheets("sheet1").Select
Range("D5") = X
Workbooks(Y).Close
Application.ScreenUpdating = True
End Sub

adjust the file pathways as needed

FYI... it's case sensitive, if your formulas output is "Ok" the change the the code to match
 
Upvote 0
thank you for the reply.

macro works perfect. I had some computer trouble. I thouht the server went down. Question got posted twice????. I don't know I didn't even think it got posted once. So I went to OZ becaue I couldn't pullup mr.excel.
sorry. I really don't know what happened.
 
Upvote 0

Forum statistics

Threads
1,215,136
Messages
6,123,243
Members
449,093
Latest member
Vincent Khandagale

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