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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
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,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

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