End If
'********************************************
TempLr = MySheet1.Cells(Rows.Count, 1).End(xlUp).Row
MySheet1.Range("b2").FormulaR1C1 = "=IFERROR(IF(RC[8]<>"""",VLOOKUP(RC[8],'MySheet2'!C[8],1,0),""""),""MySheet1 only"")"
MySheet1.Range("b2:b" & TempLr).Formula = MySheet1.Range("b2").Formula
MySheet1.Range("b2:b" & TempLr).Value = MySheet1.Range("b2:b" & TempLr).Value
MySheet1.Range("C2").FormulaR1C1 = "=COUNTIF(C[7],RC[7])"
MySheet1.Range("C2:C" & TempLr).Formula = MySheet1.Range("C2").Formula
MySheet1.Range("C2:C" & TempLr).Value = MySheet1.Range("C2:C" & TempLr).Value
TempLr = MySheet2.Cells(Rows.Count, 1).End(xlUp).Row
MySheet2.Range("b2").FormulaR1C1 = "=IFERROR(IF(RC[8]<>"""",VLOOKUP(RC[8],'Sheet Name 1'!C[8],1,0),""""),""MySheet2 only"")"
MySheet2.Range("b2:b" & TempLr).Formula = MySheet2.Range("b2").Formula
MySheet2.Range("b2:b" & TempLr).Value = MySheet2.Range("b2:b" & TempLr).Value
MySheet2.Range("C2").FormulaR1C1 = "=COUNTIF(C[7],RC[7])"
MySheet2.Range("C2:C" & TempLr).Formula = MySheet2.Range("C2").Formula
MySheet2.Range("C2:C" & TempLr).Value = MySheet2.Range("C2:C" & TempLr).Value
'*******************************************
MySheet1.Select
TempLr = MySheet1.Cells(Rows.Count, 1).End(xlUp).Row
Range("B2").FormulaR1C1 = "=IFERROR(IF(RC[8]<>"""",VLOOKUP(RC[8],'MySheet2'!C[8],1,0),""""),""MySheet1 only"")"
Range("B2:B" & TempLr).Formula = Range("B2").Formula
Range("c2").FormulaR1C1 = "=COUNTIF(C[-1],RC[-1])"
Range("c2:c" & TempLr).Formula = Range("c2").Formula
Range("B:C").Value = Range("B:C").Value
MySheet2.Select
TempLr = MySheet2.Cells(Rows.Count, 1).End(xlUp).Row
Range("B2").FormulaR1C1 = "=IFERROR(IF(RC[8]<>"""",VLOOKUP(RC[8],'Sheet Name 1'!C[8],1,0),""""),""MySheet2 only"")"
Range("B2:B" & TempLr).Formula = Range("B2").Formula
Range("c2").FormulaR1C1 = "=COUNTIF(C[-1],RC[-1])"
Range("c2:c" & TempLr).Formula = Range("c2").Formula
Range("B:C").Value = Range("B:C").Value
'Sort
MySheet2.Select
Range("A1").Select
MySheet2.AutoFilter.Sort.SortFields.Clear
MySheet2.AutoFilter.Sort.SortFields.Add Key:=MySheet2.Range(MySheet2.Cells(2, 2), MySheet2.Cells(TempLr, 2)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With MySheet2.AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
MySheet1.Select
Range("A1").Select
MySheet1.AutoFilter.Sort.SortFields.Clear
TempLr = MySheet1.Cells(Rows.Count, 1).End(xlUp).Row
MySheet1.AutoFilter.Sort.SortFields.Add Key:=MySheet1.Range(MySheet1.Cells(2, 2), MySheet1.Cells(TempLr, 2)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With MySheet1.AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'Unique
MySheet1.Columns("B:B").Copy
Sheets.Add
Dim TempSht2 As Worksheet
Set TempSht2 = ActiveSheet
ActiveSheet.Paste
ActiveSheet.Range("$A:$A").RemoveDuplicates Columns:=1, Header:=xlYes
MySheet2.Select
MySheet2.Columns("B:B").Copy
TempSht2.Range("D1").PasteSpecial
TempSht2.Range("$D:$D").RemoveDuplicates Columns:=1, Header:=xlYes
TempSht2.Select
TempLr = TempSht2.Cells(Rows.Count, 1).End(xlUp).Row
Range("B2").FormulaR1C1 = "=VLOOKUP(RC[-1],'Sheet Name 1'!C:C[1],2,0)"
Range("b2:b" & TempLr).Formula = Range("B2").Formula
Range("C2").FormulaR1C1 = "=IF(RC[-2]<>""MySheet1 only"",VLOOKUP(RC[-2],'MySheet2'!C[-1]:C,2,0),0)"
Range("C2:C" & TempLr).Formula = Range("C2").Formula
TempLr = TempSht2.Cells(Rows.Count, 4).End(xlUp).Row
Range("E2").FormulaR1C1 = "=VLOOKUP(RC[-1],'MySheet2'!C[-3]:C[-2],2,0)"
Range("E2:E" & TempLr).Formula = Range("E2").Formula
Range("F2").FormulaR1C1 = "=IF(RC[-2]<>""MySheet2 only"",VLOOKUP(RC[-2],'Sheet Name 1'!C[-4]:C[-3],2,0),0)"
Range("F2:F" & TempLr).Formula = Range("F2").Formula
Columns("A:F").ColumnWidth = 10
Dim BothTTT As Range
TempLr = TempSht2.Cells(Rows.Count, 1).End(xlUp).Row
Set BothTTT = TempSht2.Range(TempSht2.Cells(2, 1), TempSht2.Cells(TempLr, 1))
Dim BothTTTSheet As Worksheet
Sheets.Add
Set BothTTTSheet = ActiveSheet
BothTTTSheet.Name = "BothTTTSheet"
Dim TTTCount As Long
'********************************************
If TempLr <> 1 Then
TTTMapping.Range("F2").Clear
For Each rn In BothTTT
If rn.Value <> "MySheet1 only" Then
If rn.Value <> " " Then
If rn.Value <> "Only" Then
If TTTMapping.Range("F2").Value <> " " Then
TTTMapping.Range("F2").Value = rn.Value
Call MyMod3
End If
MyReport.Activate
sh.Columns("R:BF").Clear
MySheet1.Select
Range("A1").Select
Cells.Find(What:=rn, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
TTTCount = ActiveCell.Offset(0, 1).Value
ActiveCell.Offset(0, -1).Select
MySheet1.Range(MySheet1.Cells(1, 1), MySheet1.Cells(1, TempCol + 1)).Copy Destination:=sh.Cells(1, 18)
ActiveCell.Resize(TTTCount, TempCol + 1).Copy Destination:=sh.Cells(2, 18)
ActiveCell.Resize(TTTCount, 10).Value = "Only"
TempLr = BothTTTSheet.Cells(Rows.Count, 1).End(xlUp).Row + 3
MySheet2.Select
Range("A1").Select
Cells.Find(What:=rn, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
TTTCount = ActiveCell.Offset(0, 1).Value
ActiveCell.Offset(0, -1).Select
MySheet2.Range(MySheet2.Cells(1, 1), MySheet2.Cells(1, TempCol + 1)).Copy Destination:=sh.Cells(1, 40)
ActiveCell.Resize(CountSale, TempCol + 1).Copy Destination:=sh.Cells(2, 40)
ActiveCell.Resize(TTTCount, 10).Value = "Only"
ThisWorkbook.Activate
ThisWorkbook.Worksheets("Trades_In_Both_Sheet").Select
Call MyMod2
MyReport.Activate
BothTTTSheet.Range("A:Z").Clear
End If
End If
End If
Next
End If
'********************************************
MyReport.Activate
Sheets.Add
Set TTTMySheet2Sht = ActiveSheet
TTTMySheet2Sht.Name = "TTTMySheet2Sht"
TempLr = MySheet2.Cells(Rows.Count, 1).End(xlUp).Row
Set BothPresent = MySheet2.Range(MySheet2.Cells(2, 2), MySheet2.Cells(TempLr, 2))
MyReport.Activate
MySheet2.Select
MySheet2.AutoFilter.Sort.SortFields.Add Key:=MySheet2.Range(MySheet2.Cells(2, 10), MySheet2.Cells(TempLr, 10)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With MySheet2.AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
MySheet2.Range("C2").FormulaR1C1 = "=COUNTIF(C[7],RC[7])"
MySheet2.Range("C2:C" & TempLr).Formula = MySheet2.Range("C2").Formula
MySheet2.Range("C2:C" & TempLr).Value = MySheet2.Range("C2:C" & TempLr).Value
MySheet2.Select
TTTMapping.Range("F2").Clear
If TempLr <> 1 Then