I have written code to check if there is a value not equal to zero in Col D in the same row as where text "variance" appears in Col A
I want the code to check if there is a variance (Value not equal to zero) in Col D on all sheets, except the last sheet
The code runs, but does not display a message if there are any variances <> 0
In the example below Cell D5 must be displayed as there is a variance <>
Kindly amend my code pertaining to the above
I want the code to check if there is a variance (Value not equal to zero) in Col D on all sheets, except the last sheet
The code runs, but does not display a message if there are any variances <> 0
In the example below Cell D5 must be displayed as there is a variance <>
Kindly amend my code pertaining to the above
Book1 | ||||||
---|---|---|---|---|---|---|
A | B | C | D | |||
1 | BR1 | 1270 | -75217 | |||
2 | BR2 | 1271 | 50000 | |||
3 | BR3 | 1275 | 25619 | |||
4 | ||||||
5 | Variance | 402 | ||||
6 | ||||||
7 | ||||||
8 | ||||||
9 | BR1 | 1785 | -85200 | |||
10 | BR2 | 1776 | 45000 | |||
11 | BR3 | 1772 | 40200 | |||
12 | ||||||
13 | Variance | 0 | ||||
14 | ||||||
15 | ||||||
16 | ||||||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D5 | =SUM(D1:D4) | |
D13 | =SUM(D9:D12) |
Code:
Sub Variance_Message()
With Application
.CutCopyMode = False
.Calculation = xlCalculationManual
End With
Dim ws As Worksheet, r As Range, msg As String, ff As String, I As Long
For I = 1 To Count
For Each ws In Sheets(I)
Set r = ws.Columns("a").Find("Variance")
If Not r Is Nothing Then
ff = r.Address
Do
If Round(r.Offset(, 3).Value, 2) <> 0 Then
msg = msg & ws.Name & r.Address(0, 0)
End If
Set r = ws.Columns("a").FindNext(r)
Loop Until ff = r.Address
End If
Next
MsgBox IIf(Len(msg) > 0, msg, "No Variances Found")
Next I
With Application
.CutCopyMode = False
.Calculation = xlCalculationAutomatic
End With
End Sub
Last edited: