Amend Macro

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
Office Version
  1. 2021
Platform
  1. Windows
I have the following macro to determine if there are variances in col C


I would like the code amended so that when message comes up "No variances "found" , macro to end, otherwise continue with macro
Date_Message
Date_Input


Your assistance in this regard is most appreciated




Code:
 Sub Variance_Message()

Dim ws As Worksheet, r As Range, msg As String, ff As String
For Each ws In Sheets
    Set r = ws.Columns("b").Find("Variance")
    
    If Not r Is Nothing Then
        ff = r.Address
        Do
           If 5 < Abs(Val(CStr(r.Offset(0, 1).Value))) Then
               msg = msg & ws.Name & r.Address(0, 0)
            End If
            Set r = ws.Columns("b").FindNext(r)
        Loop Until ff = r.Address
    End If
   
Next
MsgBox IIf(Len(msg) > 0, msg, "No Variances Found")
Date_Message
Date_Input


End Sub


Sub Date_Message()
Sheets("Macro").Select
     MsgBox ("Remember to change the month and year")
     Sheets(2).Select
     
End Sub
Sub Date_Input()
Sheets(2).Select
Range("a3").Select
Dim MyDate As String
ActiveCell.FormulaR1C1 = InputBox("Enter the current Month and year for eg Jan 2018")

Sheets(1).Select
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Change your Msgbox to
Code:
If Len(Msg) = 0 Then
   MsgBox "No Variances Found"
   Exit Sub
Else
   MsgBox Msg
End If
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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