How to check data in two balance_sheets

excel_beginer

New Member
Joined
Dec 28, 2017
Messages
19
hello all

I have excel file with 3 sheets: Main, A and B (A,B: sheets have data of balance_sheets). So I want to check data in A,B right or wrong with conditions:

1. For each cell i (i from 2 to 15000) in sheets(A) and sheets(B)
If sheets(A)!Bi = sheets(B)!Bi and sheets(A)!Ci = sheets(B)!Ci and sheets(A)!Di = sheets(B)!Di => do nothing
else if copy row i from sheets(B) to sheets("main").

2. For each row in sheets(A) and sheets(B) I want to check data that:
if left(Ai;1) = "1" or "2" or "4" or "7" or "8" check that Ci + Ei - Fi = Gi and Di + Fi - Ei = Hi => if right do nothing but if wrong copy row i to sheets("main") in last row
if left(Ai;1) = "3" or "5" or "6" check that (Ci - Di) + (Ei - Fi) = (Gi - Hi) => if right do nothing but if wrong copy row i to sheets("main") in last row
if left(Ai;1) = "9" check that Ci + Di - Ei = Fi => if right do nothing but if wrong copy row i to sheets("main") in last row

So can you help me do 1. and 2. above to check data by code VBA?
Many thanks./.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
maybe something like this for part 1

Code:
Sub mrexcelcellmatchingtest270718()

Dim i As Long

For i = 2 To 15000

    If Worksheets("A").Range("B" & i) = Worksheets("B").Range _
        ("B" & i) And Worksheets("A").Range("C" & i) _
        = Worksheets("B").Range("C" & i) And Worksheets _
        ("A").Range("D" & i) = Worksheets("B").Range("D" & i) Then
    
    Else
    
        Worksheets("B").Rows(i).Copy
        Worksheets("main").Rows(1).Insert Shift:=xlDown
    
    End If

Next i

End Sub
 
Upvote 0
maybe this for part 2?

Code:
Sub mrexcelmatchcellpart2test270718()

Dim i As Long
Dim last_row As Long

For i = 2 To 15000

If Left(Range("A" & i).Value, 1) = 1 Or Left(Range("A" & i).Value, 1) = 2 Or _
    Left(Range("A" & i).Value, 1) = 4 Or Left(Range("A" & i).Value, 1) = 7 Or _
    Left(Range("A" & i).Value, 1) = 8 Then

    If Range("C" & i).Value + Range("E" & i).Value - Range("F" & i).Value = _
    Range("G" & i).Value And Range("D" & i).Value + Range("F" & i).Value - Range _
    ("E" & i).Value = Range("H" & i).Value Then
    
    Else
    
        last_row = Worksheets("main").Range("A1", ActiveSheet.UsedRange).Rows.Count
        Worksheets("B").Rows(i).Copy Destination:=Worksheets("main").Cells(last_row + 1, "A")
    End If
    
    If Left(Range("A" & i).Value, 1) = 3 Or Left(Range("A" & i).Value, 1) = 5 Or _
    Left(Range("A" & i).Value, 1) = 6 Then
    
        If (Range("C" & i).Value - Range("D" & i).Value) + (Range("E" & i).Value - Range("F" & i).Value) = (Range("G" & i).Value - Range("H" & i).Value) Then
        
        Else
        
            last_row = Worksheets("main").Range("A1", ActiveSheet.UsedRange).Rows.Count
            Worksheets("B").Rows(i).Copy Destination:=Worksheets("main").Cells(last_row + 1, "A")
        End If
        
        If Left(Range("A" & i).Value, 1) = 9 Then
            
            If Range("C" & i).Value + Range("D" & i).Value - Range("E" & i).Value = Range("F" & i).Value Then
                
            Else
                
                last_row = Worksheets("main").Range("A1", ActiveSheet.UsedRange).Rows.Count
                Worksheets("B").Rows(i).Copy Destination:=Worksheets("main").Cells(last_row + 1, "A")
            End If
                
        End If
    
    End If
    
End If

Next i

End Sub

there's probably a better way but this is all i can do with what i know. just hope it works
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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