Hi experts ,
I put the result in column column D,E for sheet2 and highlighted new item for sheet1,2
so current code compares data between two sheets based on column B , subtraction numeric values between two sheets and result show in column E for sheet2 , if the values are positive or negative then will be in column D wrong mark for adjacent cell and if the value is zero or empty in column E will be in column D right mark and if there new item is existed in sheet but it's not in the other will highlight the item by red . if the item is in existed in sheet1 , but it's not existed in sheet2 the value in column E is negative, if the item is in existed in sheet2 but not in sheet1 the value in column E is positive
so I want replace formula in column D with vba procedure and highlight new items between two sheets .
should copy highlighted data from sheet1 to sheet2 to become as I put in rang I: M but the result should be in range A:E
also posted here
vba compare between two sheets and highlight new items
final result
I put the result in column column D,E for sheet2 and highlighted new item for sheet1,2
so current code compares data between two sheets based on column B , subtraction numeric values between two sheets and result show in column E for sheet2 , if the values are positive or negative then will be in column D wrong mark for adjacent cell and if the value is zero or empty in column E will be in column D right mark and if there new item is existed in sheet but it's not in the other will highlight the item by red . if the item is in existed in sheet1 , but it's not existed in sheet2 the value in column E is negative, if the item is in existed in sheet2 but not in sheet1 the value in column E is positive
so I want replace formula in column D with vba procedure and highlight new items between two sheets .
should copy highlighted data from sheet1 to sheet2 to become as I put in rang I: M but the result should be in range A:E
also posted here
vba compare between two sheets and highlight new items
VBA Code:
Sub UpdateSheet2()
Dim LR As Long
With Sheets("Sheet2")
LR = .Range("B" & .Rows.Count).End(xlUp).Row
With .Range("E2:E" & LR)
.Formula = "=IF(ISNUMBER(MATCH(B2, Sheet1!B:B, 0)), C2 - VLOOKUP(B2, Sheet1!B:C, 2, 0), C2)"
.Value = .Value
End With
End With
End Sub
COMPARE.xlsm | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | ITEM | BRAND | QTY | ||
2 | 1 | 10W40 208L | 55 | ||
3 | 2 | 15W40 208L | 20 | ||
4 | 3 | 5W30 208L | 10 | ||
5 | 4 | 5W30 12x1L | 10 | ||
6 | 5 | 5W30 4x4L | 4 | ||
7 | 6 | 10W40 12x4L | 45 | ||
8 | 7 | 15W40 12x1L | 8 | ||
9 | 8 | 10W40 12x1L | 1 | ||
10 | 9 | 10W40 4x5L | 22 | ||
11 | 10 | 10W40 4x1L | 20 | ||
12 | 11 | 5W40 4x6L | 44 | ||
13 | 12 | 5W40 4x4L | 20 | ||
14 | 13 | 5W40 4x5L | 50 | ||
15 | 14 | 20W50 4x4L | 9 | ||
16 | 15 | 20W50 4x10L | 5 | ||
sheet1 |
COMPARE.xlsm | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | ITEM | BRAND | QTY | CONDITION | RESULT | ||
2 | 1 | 15W40 12x1L | 18 | û | 10 | ||
3 | 2 | 10W40 12x1L | 40 | û | 39 | ||
4 | 3 | 10W40 4x5L | 11 | û | -11 | ||
5 | 4 | 10W40 4x1L | 9 | û | -11 | ||
6 | 5 | 5W40 4x6L | 4 | û | -40 | ||
7 | 6 | 5W40 4x4L | 4 | û | -16 | ||
8 | 7 | 5W40 4x5L | 45 | û | -5 | ||
9 | 8 | 20W50 4x4L | 8 | û | -1 | ||
10 | 9 | 10W40 208L | 1 | û | -54 | ||
11 | 10 | 15W40 208L | 33 | û | 13 | ||
12 | 11 | 5W30 208L | 21 | û | 11 | ||
13 | 12 | 5W30 12x1L | 10 | ü | 0 | ||
14 | 13 | 20W50 4x1L | 4 | û | 4 | ||
sheet2 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D2:D14 | D2 | =IF(E2=0,CHAR(252),CHAR(251)) |
final result
COMPARE.xlsm | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
1 | ITEM | BRAND | QTY | CONDITION | RESULT | ||
2 | 1 | 15W40 12x1L | 18 | û | 10 | ||
3 | 2 | 10W40 12x1L | 40 | û | 39 | ||
4 | 3 | 10W40 4x5L | 11 | û | -11 | ||
5 | 4 | 10W40 4x1L | 9 | û | -11 | ||
6 | 5 | 5W40 4x6L | 4 | û | -40 | ||
7 | 6 | 5W40 4x4L | 4 | û | -16 | ||
8 | 7 | 5W40 4x5L | 45 | û | -5 | ||
9 | 8 | 20W50 4x4L | 8 | û | -1 | ||
10 | 9 | 10W40 208L | 1 | û | -54 | ||
11 | 10 | 15W40 208L | 33 | û | 13 | ||
12 | 11 | 5W30 208L | 21 | û | 11 | ||
13 | 12 | 5W30 12x1L | 10 | ü | 0 | ||
14 | 13 | 20W50 4x1L | 4 | û | 4 | ||
15 | 14 | 5W30 4x4L | 4 | û | -4 | ||
16 | 15 | 10W40 12x4L | 45 | û | -45 | ||
17 | 16 | 20W50 4x10L | 5 | û | -5 | ||
sheet2 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D2:D17 | D2 | =IF(E2=0,CHAR(252),CHAR(251)) |