Validation coherence between cells in different sheets

NerakSeven

New Member
Joined
Jan 6, 2019
Messages
14
Im trying to create a macro for to check the coherence between sheets. I have two sheets ( a and b ) and I need check for the same code declared in both sheets in the field "code" have the same number in the field "system" and this true put "ok" in field "validation" in sheet B

Example
SHEET A
Code **** system***
221. ****15
331.**** 0
114. ****90
SHEET B
Code****system *****validation
221 ****15. ****Ok
331.*** 1.*** Fail
114. ***90. ***OK

Im newbie in vba please help me

Regards
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
In which columns are the Code, system and validation in each sheet? What the actual sheet names?
 
Upvote 0
In which columns are the Code, system and validation in each sheet? What the actual sheet names?



The actual sheet names are 101 and 1704
And columns for 101 :
Code :“C”
System: “B”
For 1704
Code :“F”
Sytsem: “B”
Validation: “H”
 
Upvote 0
Try:
Code:
Sub compareVals()
    Application.ScreenUpdating = False
    Dim LastRow As Long, code As Range, fCode As Range, rng101 As Range, rng1704 As Range
    Set rng101 = Sheets("101").Range("C2", Sheets("101").Range("C" & Sheets("101").Rows.Count).End(xlUp))
    Set rng1704 = Sheets("1704").Range("F2", Sheets("1704").Range("F" & Sheets("1704").Rows.Count).End(xlUp))
    For Each code In rng101
        Set fCode = rng1704.Find(code, LookIn:=xlValues, lookat:=xlWhole)
        If Not fCode Is Nothing Then
            If fCode.Offset(0, -4) = code.Offset(0, -1) Then
                fCode.Offset(0, 2) = "OK"
            Else
                fCode.Offset(0, 2) = "Fail"
            End If
        End If
    Next code
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
The code no put the value “Fail” and works only for the first code. I mean if the code is repeated in sheet the code is not validated. How I fix this?
Please
 
Upvote 0
Try:
Code:
Sub compareVals()
    Application.ScreenUpdating = False
    Dim LastRow As Long, code As Range, fCode As Range, rng101 As Range, rng1704 As Range, sAddr As String
    Set rng101 = Sheets("101").Range("C2", Sheets("101").Range("C" & Sheets("101").Rows.Count).End(xlUp))
    Set rng1704 = Sheets("1704").Range("F2", Sheets("1704").Range("F" & Sheets("1704").Rows.Count).End(xlUp))
    For Each code In rng101
        Set fCode = rng1704.Find(code, LookIn:=xlValues, lookat:=xlWhole)
        If Not fCode Is Nothing Then
            sAddr = fCode.Address
            Do
                If fCode.Offset(0, -4) = code.Offset(0, -1) Then
                    fCode.Offset(0, 2) = "OK"
                Else
                    fCode.Offset(0, 2) = "Fail"
                End If
                Set fCode = rng1704.FindNext(fCode)
            Loop While fCode.Address <> sAddr
            sAddr = ""
        End If
    Next code
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,464
Messages
6,055,573
Members
444,799
Latest member
CraigCrowhurst

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