I'm trying to run a macro that will first search for the cell and check the value next to the cell and if the cell = 0, get message-box "no differences" if the cell <>0 go to sheet. I want to do this for different sheets in the same workbook.

Sub Check()
'To check unaccounted difference in all sheets
Sheets("443000-jan").Select
    Cells.Find(what:="Unaccounted Diff").Select
    ActiveCell.Select
    ActiveCell.Offset(0, 1).Select
        If ActiveCell.Value = 0 Then
        MsgBox "No Differences Found"
       ElseIf ActiveCell.Values <> 0 Then
        Worksheets("443000-Jan").Visible = True
        Worksheets("443000-Jan").Activate
  End If
   Sheets("443001-SC").Select
    Cells.Find(what:="Unaccounted Diff").Select
    ActiveCell.Select
    ActiveCell.Offset(0, 1).Select
        If ActiveCell.Value = 0 Then
        MsgBox "No Differences Found"
       ElseIf ActiveCell.Values <> 0 Then
        Worksheets("443001-SC").Visible = True
        Worksheets("443001-SC").Activate

    End If

 End Sub

1 Answers

0
QuickSilver On

Assuming that you want to check that for all the sheets in a workbook you need to loop through. You will need to look at not using the select all over the place. I think it would be better if you assign the .find value to a variable and use that in your code.

Sub LoopSheets()
Dim WS as Worksheet

  For Each WS In ActiveWorkbook.Worksheets
  If Worksheets(WS).Name <> “Master” Then
     Cells.Find(what:="Unaccounted Diff").Select
         ActiveCell.Offset(0, 1).Select
         If ActiveCell.Value = 0 Then
            MsgBox "No Differences Found"
        ElseIf ActiveCell.Values <> 0 Then
            WS.Visible = True
            WS.Activate
        End If     
   End If
  Next WS
End Sub