Compare two sheets based on lastrow with highlighted cells

abdo meghari

Well-known Member
Joined
Aug 3, 2021
Messages
613
Office Version
  1. 2019
Hi,
I have two sheets contains data and every time the last row will change in location so what I want compare amount in lastrow for column F in INVOICE sheet with amount in lastrow for column E in ACCOUNT sheet .if the amount in last row in ACCOUNT sheet bigger than amount in last row in INVOICE sheet then will highlighted by red and write the difference for adjacent cell by plus or deficit and amount , and if it's matched the amounts between two sheets then will highlighted yellow and write matched .
will show result for both sheets in last amount in last column .
example:
COMPARE.xlsm
BCDEF
21ITEMBRANDQTYPRICEBALANCE
221VEGA 70A R KOR4.00500.002,000.00
232VEGA 55A R KOR2.00425.00850.00
243LARGEST 60A L HIGH JAP2.00440.00880.00
254KM 215/65R16 TA31 KOR4.00460.001,840.00
265265/70R16 ALGERIA4.00630.002,520.00
276KM 205/65R16 HS63 KOR4.00445.001,780.00
287GC 385/65R22.5 AT131 CHI2.001,650.003,300.00
298KM 265/70R16 KOR4.00880.003,520.00
309DONGA 66A L KOR2.00460.00920.00
3110KM 235/65R17 HP71 KOR4.00625.002,500.00
3211KM 235/55R19 PS71 KOR4.00675.002,700.00
3312DROUB 90A L KOR1.00575.00575.00
3413KM 13R22.5 MA11 KOR2.002,550.005,100.00
35TOTAL39.0028,485.00
INVOICE
Cell Formulas
RangeFormula
D35,F35D35=SUM(D22:D34)
F22:F34F22=D22*E22



COMPARE.xlsm
ABCDE
1DATEINFODEBITCREDITBALANCE
201/11/2024SALES INVOICE NO BSJ20002,000.002,000.00
302/11/2024SALES INVOICE NO BSJ20013,000.005,000.00
403/11/2024SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
503/11/2024VOUCHER NO VBGH67881,500.00500.00
604/11/2024SALES INVOICE NO BSJ200315,000.0015,500.00
704/11/2024SALES INVOICE NO BSJ200413,000.0028,500.00
8
9
10
11
12
13
14
15
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E7E3=E2+C3-D3



result

COMPARE.xlsm
ABCDEF
1DATEINFODEBITCREDITBALANCE
201/11/2024SALES INVOICE NO BSJ20002,000.002,000.00
302/11/2024SALES INVOICE NO BSJ20013,000.005,000.00
403/11/2024SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
503/11/2024VOUCHER NO VBGH67881,500.00500.00
604/11/2024SALES INVOICE NO BSJ200315,000.0015,500.00
704/11/2024SALES INVOICE NO BSJ200413,000.0028,500.00PLUS 15.00
8
9
10
11
12
13
14
15
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E7E3=E2+C3-D3




COMPARE.xlsm
BCDEFG
21ITEMBRANDQTYPRICEBALANCE
221VEGA 70A R KOR4.00500.002,000.00
232VEGA 55A R KOR2.00425.00850.00
243LARGEST 60A L HIGH JAP2.00440.00880.00
254KM 215/65R16 TA31 KOR4.00460.001,840.00
265265/70R16 ALGERIA4.00630.002,520.00
276KM 205/65R16 HS63 KOR4.00445.001,780.00
287GC 385/65R22.5 AT131 CHI2.001,650.003,300.00
298KM 265/70R16 KOR4.00880.003,520.00
309DONGA 66A L KOR2.00460.00920.00
3110KM 235/65R17 HP71 KOR4.00625.002,500.00
3211KM 235/55R19 PS71 KOR4.00675.002,700.00
3312DROUB 90A L KOR1.00575.00575.00
3413KM 13R22.5 MA11 KOR2.002,550.005,100.00
35TOTAL39.0028,485.00DEFICIT -15.00
INVOICE
Cell Formulas
RangeFormula
D35,F35D35=SUM(D22:D34)
F22:F34F22=D22*E22



another example

COMPARE.xlsm
BCDEF
21ITEMBRANDQTYPRICEBALANCE
221VEGA 70A R KOR4.00500.002,000.00
232VEGA 55A R KOR2.00425.00850.00
243LARGEST 60A L HIGH JAP2.00440.00880.00
254KM 215/65R16 TA31 KOR4.00460.001,840.00
265265/70R16 ALGERIA4.00630.002,520.00
276KM 205/65R16 HS63 KOR4.00445.001,780.00
287GC 385/65R22.5 AT131 CHI2.001,650.003,300.00
298KM 265/70R16 KOR4.00880.003,520.00
309DONGA 66A L KOR2.00460.00920.00
3110KM 235/65R17 HP71 KOR4.00625.002,500.00
3211KM 235/55R19 PS71 KOR4.00675.002,700.00
3312XCV 90A L KOR1.00580.00580.00
3413BJS 13R22.5 MA11 KOR2.002,555.005,110.00
3514KM 13R22.5 MA11 KOR5.002,000.0010,000.00
36TOTAL44.0038,500.00
INVOICE
Cell Formulas
RangeFormula
D36,F36D36=SUM(D22:D35)
F22:F35F22=D22*E22


COMPARE.xlsm
ABCDEF
1DATEINFODEBITCREDITBALANCE
201/11/2024SALES INVOICE NO BSJ20002,000.002,000.00
302/11/2024SALES INVOICE NO BSJ20013,000.005,000.00
403/11/2024SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
503/11/2024VOUCHER NO VBGH67881,500.00500.00
604/11/2024SALES INVOICE NO BSJ200315,000.0015,500.00
704/11/2024SALES INVOICE NO BSJ200413,000.0028,500.00PLUS 15.00
805/11/2024SALES INVOICE NO BSJ200515,000.0043,500.00
905/11/2024SALES INVOICE NO BSJ20061,000.0044,500.00
1005/11/2024VOUCHER NO VBGH67891,000.0043,500.00
1105/11/2024VOUCHER NO VBGH67905,000.0038,500.00
12
13
14
15
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E11E3=E2+C3-D3



result
COMPARE.xlsm
BCDEFG
21ITEMBRANDQTYPRICEBALANCE
221VEGA 70A R KOR4.00500.002,000.00
232VEGA 55A R KOR2.00425.00850.00
243LARGEST 60A L HIGH JAP2.00440.00880.00
254KM 215/65R16 TA31 KOR4.00460.001,840.00
265265/70R16 ALGERIA4.00630.002,520.00
276KM 205/65R16 HS63 KOR4.00445.001,780.00
287GC 385/65R22.5 AT131 CHI2.001,650.003,300.00
298KM 265/70R16 KOR4.00880.003,520.00
309DONGA 66A L KOR2.00460.00920.00
3110KM 235/65R17 HP71 KOR4.00625.002,500.00
3211KM 235/55R19 PS71 KOR4.00675.002,700.00
3312XCV 90A L KOR1.00580.00580.00
3413BJS 13R22.5 MA11 KOR2.002,555.005,110.00
3514KM 13R22.5 MA11 KOR5.002,000.0010,000.00
36TOTAL44.0038,500.00MATCHED
INVOICE
Cell Formulas
RangeFormula
D36,F36D36=SUM(D22:D35)
F22:F35F22=D22*E22



COMPARE.xlsm
ABCDEF
1DATEINFODEBITCREDITBALANCE
201/11/2024SALES INVOICE NO BSJ20002,000.002,000.00
302/11/2024SALES INVOICE NO BSJ20013,000.005,000.00
403/11/2024SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
503/11/2024VOUCHER NO VBGH67881,500.00500.00
604/11/2024SALES INVOICE NO BSJ200315,000.0015,500.00
704/11/2024SALES INVOICE NO BSJ200413,000.0028,500.00PLUS 15.00
805/11/2024SALES INVOICE NO BSJ200515,000.0043,500.00
905/11/2024SALES INVOICE NO BSJ20061,000.0044,500.00
1005/11/2024VOUCHER NO VBGH67891,000.0043,500.00
1105/11/2024VOUCHER NO VBGH67905,000.0038,500.00MATCHED
12
13
14
15
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E11E3=E2+C3-D3


Last example
COMPARE.xlsm
BCDEF
21ITEMBRANDQTYPRICEBALANCE
221BJS 13R22.5 MA11 KOR10.002,555.0025,550.00
232KM 13R22.5 MA11 KOR12.002,000.0024,000.00
24TOTAL22.0049,550.00
INVOICE
Cell Formulas
RangeFormula
D24,F24D24=SUM(D22:D23)
F22:F23F22=D22*E22


COMPARE.xlsm
ABCDEF
1DATEINFODEBITCREDITBALANCE
201/11/2024SALES INVOICE NO BSJ20002,000.002,000.00
302/11/2024SALES INVOICE NO BSJ20013,000.005,000.00
403/11/2024SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
503/11/2024VOUCHER NO VBGH67881,500.00500.00
604/11/2024SALES INVOICE NO BSJ200315,000.0015,500.00
704/11/2024SALES INVOICE NO BSJ200413,000.0028,500.00PLUS 15.00
805/11/2024SALES INVOICE NO BSJ200515,000.0043,500.00
905/11/2024SALES INVOICE NO BSJ20061,000.0044,500.00
1005/11/2024VOUCHER NO VBGH67891,000.0043,500.00
1105/11/2024VOUCHER NO VBGH67905,000.0038,500.00MATCHED
1205/11/2024SALES INVOICE NO BSJ20072,000.0040,500.00
1305/11/2024SALES INVOICE NO BSJ20083,000.0043,500.00
1405/11/2024SALES INVOICE NO BSJ20095,000.0048,500.00
15
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E14E3=E2+C3-D3



result

COMPARE.xlsm
BCDEFG
21ITEMBRANDQTYPRICEBALANCE
221BJS 13R22.5 MA11 KOR10.002,555.0025,550.00
232KM 13R22.5 MA11 KOR12.002,000.0024,000.00
24TOTAL22.0049,550.00PLUS 1,050.00
INVOICE
Cell Formulas
RangeFormula
D24,F24D24=SUM(D22:D23)
F22:F23F22=D22*E22



COMPARE.xlsm
ABCDEFG
1DATEINFODEBITCREDITBALANCE
201/11/2024SALES INVOICE NO BSJ20002,000.002,000.00
302/11/2024SALES INVOICE NO BSJ20013,000.005,000.00
403/11/2024SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
503/11/2024VOUCHER NO VBGH67881,500.00500.00
604/11/2024SALES INVOICE NO BSJ200315,000.0015,500.00
704/11/2024SALES INVOICE NO BSJ200413,000.0028,500.00PLUS 15.00
805/11/2024SALES INVOICE NO BSJ200515,000.0043,500.00
905/11/2024SALES INVOICE NO BSJ20061,000.0044,500.00
1005/11/2024VOUCHER NO VBGH67891,000.0043,500.00
1105/11/2024VOUCHER NO VBGH67905,000.0038,500.00MATCHED
1205/11/2024SALES INVOICE NO BSJ20072,000.0040,500.00
1305/11/2024SALES INVOICE NO BSJ20083,000.0043,500.00
1405/11/2024SALES INVOICE NO BSJ20095,000.0048,500.00DEFICIT -1,050.00
15
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E14E3=E2+C3-D3
 
COMPARE.xlsm
BCDEFG
21ITEMBRANDQTYPRICEBALANCE
221BJS 13R22.5 MA11 KOR10255525550
232KM 14R22.5 MA11 KOR12200024000
243KM 15R22.5 MA11 KOR10100010000
254KM 16R22.5 MA11 KOR10100010000
26TOTAL3269550PLUS -34003
INVOICE
Cell Formulas
RangeFormula
D26D26=SUM(D22:D24)
F22:F25F22=D22*E22
F26F26=SUM(F22:F25)
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Using the values 48,500.00 and 69550 in these two sheets, the difference is 21050 not 1,050 or 34003.
 
Upvote 0
Using the values 48,500.00 and 69550 in these two sheets, the difference is 21050 not 1,050 or 34003.

I changed value manually to test it.
but what about this?!
COMPARE.xlsm
BCDEFG
21ITEMBRANDQTYPRICEBALANCE
221BJS 13R22.5 MA11 KOR10255525550
232KM 14R22.5 MA11 KOR12200024000
243KM 15R22.5 MA11 KOR10100010000
254KM 16R22.5 MA11 KOR10100010000
265KM 16R22.5 MA11 KOR20250050000
27TOTAL32119550PLUS -52126
INVOICE
Cell Formulas
RangeFormula
D27D27=SUM(D22:D24)
F22:F26F22=D22*E22
F27F27=SUM(F22:F26)



COMPARE.xlsm
ABCDEF
1DATEINFODEBITCREDITBALANCE
201/11/2024SALES INVOICE NO BSJ20002,000.002,000.00
302/11/2024SALES INVOICE NO BSJ20013,000.005,000.00
403/11/2024SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
503/11/2024VOUCHER NO VBGH67881,500.00500.00
604/11/2024SALES INVOICE NO BSJ200315,000.0015,500.00
704/11/2024SALES INVOICE NO BSJ200413,000.0028,500.00DEFICIT -41050
805/11/2024SALES INVOICE NO BSJ200513,001.0041,501.00
906/11/2024SALES INVOICE NO BSJ200613,002.0054,503.00
1007/11/2024SALES INVOICE NO BSJ200713,003.0067,506.00
1108/11/2024SALES INVOICE NO BSJ200813,004.0080,510.00
1209/11/2024SALES INVOICE NO BSJ200913,005.0093,515.00
1310/11/2024SALES INVOICE NO BSJ201013,006.00106,521.00
1411/11/2024SALES INVOICE NO BSJ201113,029.00119,550.00MATCHED
1512/11/2024SALES INVOICE NO BSJ201213,030.00132,580.00
1613/11/2024SALES INVOICE NO BSJ201313,031.00145,611.00
1714/11/2024SALES INVOICE NO BSJ201413,032.00158,643.00
1815/11/2024SALES INVOICE NO BSJ201513,033.00171,676.00DEFICIT 52126
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E18E3=E2+C3-D3


in ACCOUNT sheet should be PLUS 52126 and in INVOICE sheet should be DEFICIT- 52126
 
Upvote 0
This works for me:'
VBA Code:
Sub CompareValues()
    Application.ScreenUpdating = False
    Dim invWS As Worksheet, accWS As Worksheet, lRowInv As Long, lRowAcc As Long
    Set invWS = Sheets("INVOICE")
    Set accWS = Sheets("ACCOUNT")
    lRowInv = invWS.Range("F" & Rows.Count).End(xlUp).Row
    lRowAcc = accWS.Range("E" & Rows.Count).End(xlUp).Row
    If accWS.Range("E" & lRowAcc).Value > invWS.Range("F" & lRowInv).Value Or accWS.Range("E" & lRowAcc).Value < invWS.Range("F" & lRowInv).Value Then
        accWS.Range("E" & lRowAcc).Interior.ColorIndex = 3
        accWS.Range("F" & lRowAcc) = "DEFICIT " & accWS.Range("E" & lRowAcc).Value - invWS.Range("F" & lRowInv).Value
        invWS.Range("F" & lRowInv).Interior.ColorIndex = 3
        invWS.Range("G" & lRowInv).Value = "PLUS " & invWS.Range("F" & lRowInv).Value - accWS.Range("E" & lRowAcc).Value
    ElseIf accWS.Range("E" & lRowAcc).Value = invWS.Range("F" & lRowInv).Value Then
        accWS.Range("E" & lRowAcc).Interior.ColorIndex = 6
        accWS.Range("F" & lRowAcc) = "MATCHED "
        invWS.Range("F" & lRowInv).Interior.ColorIndex = 6
        invWS.Range("G" & lRowInv) = "MATCHED"
    End If
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
The macro worked properly with your file as well.
 
Upvote 0
so you want to say the values are saved in my file change to right like plus DEFICIT 52126 in ACCOUNT sheet ,DEFICIT -52126 in INVOICE sheet ?
 
Upvote 0
Yes. This is what I got when I ran the macro.
COMPARE.xlsm
ABCDEF
1DATEINFODEBITCREDITBALANCE
22024-11-01SALES INVOICE NO BSJ20002,000.002,000.00
32024-11-02SALES INVOICE NO BSJ20013,000.005,000.00
42024-11-03SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
52024-11-03VOUCHER NO VBGH67881,500.00500.00
62024-11-04SALES INVOICE NO BSJ200315,000.0015,500.00
72024-11-04SALES INVOICE NO BSJ200413,000.0028,500.00DEFICIT -41050
82024-11-05SALES INVOICE NO BSJ200513,001.0041,501.00
92024-11-06SALES INVOICE NO BSJ200613,002.0054,503.00
102024-11-07SALES INVOICE NO BSJ200713,003.0067,506.00
112024-11-08SALES INVOICE NO BSJ200813,004.0080,510.00
122024-11-09SALES INVOICE NO BSJ200913,005.0093,515.00
132024-11-10SALES INVOICE NO BSJ201013,006.00106,521.00
142024-11-11SALES INVOICE NO BSJ201113,029.00119,550.00MATCHED
152024-11-12SALES INVOICE NO BSJ201213,030.00132,580.00
162024-11-13SALES INVOICE NO BSJ201313,031.00145,611.00
172024-11-14SALES INVOICE NO BSJ201413,032.00158,643.00
182024-11-15SALES INVOICE NO BSJ201513,033.00171,676.00DEFICIT 52126
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E18E3=E2+C3-D3


COMPARE.xlsm
BCDEFG
21ITEMBRANDQTYPRICEBALANCE
221BJS 13R22.5 MA11 KOR10255525550
232KM 14R22.5 MA11 KOR12200024000
243KM 15R22.5 MA11 KOR10100010000
254KM 16R22.5 MA11 KOR10100010000
265KM 16R22.5 MA11 KOR20250050000
27TOTAL32119550PLUS -52126
INVOICE
Cell Formulas
RangeFormula
D27D27=SUM(D22:D24)
F22:F26F22=D22*E22
F27F27=SUM(F22:F26)
 
Upvote 0
this is the same result for me !:eek:
may you read well my last post about values and words how should be please?

this is the correct result for both sheets
COMPARE.xlsm
BCDEFG
21ITEMBRANDQTYPRICEBALANCE
221BJS 13R22.5 MA11 KOR10255525550
232KM 14R22.5 MA11 KOR12200024000
243KM 15R22.5 MA11 KOR10100010000
254KM 16R22.5 MA11 KOR10100010000
265KM 16R22.5 MA11 KOR20250050000
27TOTAL32119550DEFICIT -52126
INVOICE
Cell Formulas
RangeFormula
D27D27=SUM(D22:D24)
F22:F26F22=D22*E22
F27F27=SUM(F22:F26)


COMPARE.xlsm
ABCDEF
1DATEINFODEBITCREDITBALANCE
201/11/2024SALES INVOICE NO BSJ20002,000.002,000.00
302/11/2024SALES INVOICE NO BSJ20013,000.005,000.00
403/11/2024SALES RETURNS INVOICE NO BSJ7893,000.002,000.00
503/11/2024VOUCHER NO VBGH67881,500.00500.00
604/11/2024SALES INVOICE NO BSJ200315,000.0015,500.00
704/11/2024SALES INVOICE NO BSJ200413,000.0028,500.00DEFICIT -41050
805/11/2024SALES INVOICE NO BSJ200513,001.0041,501.00
906/11/2024SALES INVOICE NO BSJ200613,002.0054,503.00
1007/11/2024SALES INVOICE NO BSJ200713,003.0067,506.00
1108/11/2024SALES INVOICE NO BSJ200813,004.0080,510.00
1209/11/2024SALES INVOICE NO BSJ200913,005.0093,515.00
1310/11/2024SALES INVOICE NO BSJ201013,006.00106,521.00
1411/11/2024SALES INVOICE NO BSJ201113,029.00119,550.00MATCHED
1512/11/2024SALES INVOICE NO BSJ201213,030.00132,580.00
1613/11/2024SALES INVOICE NO BSJ201313,031.00145,611.00
1714/11/2024SALES INVOICE NO BSJ201413,032.00158,643.00
1815/11/2024SALES INVOICE NO BSJ201513,033.00171,676.00PLUS 52126
ACCOUNT
Cell Formulas
RangeFormula
E2E2=C2-D2
E3:E18E3=E2+C3-D3
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,601
Members
452,658
Latest member
GStorm

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