Msg.Box depending on the value of a cell

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello guys
With this code, I am getting the same message "Matched" even if it is "Mismatch". Please guide me to correct the code.
Rich (BB code):
Option Explicit
Sub test()
Dim r As Long
Dim cnt As Long
cnt = 0
Application.ScreenUpdating = False
r = Cells(Rows.Count, 6).End(3).Row - 2
[g1] = "Check"
[g2] = "=F2"
[g3].Resize(r) = "=G2+D3-E3"
[H1] = "=IF(F" & r + 2 & "=G" & r + 2 & ",""Matched"",""Mismatch"")"
[h2].Resize(r + 1) = "=F2=G2"
[g1].Resize(, 2).Font.Bold = True
Columns("G:H").AutoFit
Application.ScreenUpdating = True
Select Case cnt
Case 1
    Range("H1").Activate
    MsgBox "MisMatch."
   
   Case Else
    Range("H1").Activate
    MsgBox "Matched"
End Select
Range("H1").Activate
End Sub
Query code to check and match.xlsm
ABCDEFGH
1Dr AmountCr AmountBalanceCheckMismatch
21890.0020091859.9520091859.95TRUE
313000.0020078859.9520078859.95TRUE
44750.0020074109.9520074109.95TRUE
5326.0020073783.9520073783.95TRUE
620063783.9520073783.95FALSE
722000.0020041783.9520051783.95FALSE
821484.0020020299.9520030299.95FALSE
98361.0020011938.9520021938.95FALSE
107925.0020004013.9520014013.95FALSE
113000.0020007013.9520017013.95FALSE
1220000.0020027013.9520037013.95FALSE
1315000.0020042013.9520052013.95FALSE
14673.0020041340.9520051340.95FALSE
1510044.0020031296.9520041296.95FALSE
167000.0020024296.9520034296.95FALSE
Match
Cell Formulas
RangeFormula
H1H1=IF(F16=G16,"Matched","Mismatch")
G2G2=F2
H2:H16H2=F2=G2
G3:G16G3=G2+D3-E3
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Solved. Replaced it with one line
MsgBox [H1].value
 
Upvote 0
With your code, you have:
cnt = 0

Later you have:
VBA Code:
Select Case cnt
Case 1
    Range("H1").Activate
    MsgBox "MisMatch."
   
   Case Else
    Range("H1").Activate
    MsgBox "Matched"
End Select

You don't change the cnt initial value of 0, therefore you will always get the same message box result.
 
Upvote 0
With your code, you have:
cnt = 0

Later you have:
VBA Code:
Select Case cnt
Case 1
    Range("H1").Activate
    MsgBox "MisMatch."
  
   Case Else
    Range("H1").Activate
    MsgBox "Matched"
End Select

You don't change the cnt initial value of 0, therefore you will always get the same message box result.
I just copied the code from the previous threads in the forum and tried to edit it. ?
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,084
Members
448,943
Latest member
sharmarick

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