Search and return new values???

erwin_m29

New Member
Joined
Sep 9, 2014
Messages
4
I have multiple given values in Sheet 1, range a1:a200.
1st day i have to update Sheet 2, range a1:a200, and find ouf if this values matches the values
on Sheet 1, range a1:a200, if match found, i will write Y in day 1, if not i will write N.
day 2, i will again update Sheet 2, range a1:a200, and find out if this values matches from sheet 1, range a1:a200,
if match found, i will write y on day 2 column, if not, will write N... so on and so fort...

Sheet 1

Data1day1day2day3
AAAAAAY
AAABBBN
AAACCCY
AAADDDY

<tbody>
</tbody>


Sheet 2
AAAAAAA
AAACCC
AAADDD

<tbody>
</tbody>


Any suggestion how to solve this problem, in just a click?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

hohlick

New Member
Joined
Sep 9, 2014
Messages
16
I suggest you can use this formula on Sheet2: =IF(ISNA(MATCH(A1,Sheet1!$A$1:$A$200,0)),"N","Y") where A1 is the first cell on Sheet2 with updated values, and then fill it down to cell A200. After that, you need to replace formulas in A1:A200 on Sheet2 with values. Next day you should repeat this
Hope it helps
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Assuming you update cells A1:A200 only once a day, then you can run this macro immediately after doing the daily update...
Code:
Sub Update()
  Dim LastRow As Long, NextDay As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  NextDay = Cells(2, Columns.Count).End(xlToLeft).Column + 1
  With Cells(2, NextDay).Resize(LastRow - 1)
    .Formula = "=IF(COUNTIF(Sheet2!$A$1:$A$200,$A2),""Y"",""N"")"
    .Value = .Value
  End With
End Sub
 
Upvote 0

erwin_m29

New Member
Joined
Sep 9, 2014
Messages
4
thank yall for the quick response.

for rick, your solution works perfectly, thank you.
i have another conditions to add.
after writing Y, it will format the cell with fill color GREEN.
while if it is N, the cell will be colored RED.
how would u add this to your macro?
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
i have another conditions to add.
after writing Y, it will format the cell with fill color GREEN.
while if it is N, the cell will be colored RED.
how would u add this to your macro?

Give this modified version of the code I posted earlier a try...

Code:
Sub Update()
  Dim LastRow As Long, NextDay As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  NextDay = Cells(2, Columns.Count).End(xlToLeft).Column + 1
  With Cells(2, NextDay).Resize(LastRow - 1)
    .Formula = "=IF(COUNTIF(Sheet2!$A$1:$A$200,$A2),""Y"",""N"")"
    .Value = .Value
    .Interior.ColorIndex = 3
    Application.ReplaceFormat.Clear
    Application.ReplaceFormat.Interior.ColorIndex = 4
    .Replace "Y", "", xlWhole, ReplaceFormat:=True
    Application.ReplaceFormat.Clear
  End With
End Sub
 
Upvote 0

erwin_m29

New Member
Joined
Sep 9, 2014
Messages
4
you are so awesome mr rick.
im trying to understand the command lines, what if i modify my sheet1 (eg i added headings, so i move my data to fr A1:A200 to A3:A203 (A1 to A2 rows will be assign for table heading).
which command lines manages this condition?
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
you are so awesome mr rick.
im trying to understand the command lines, what if i modify my sheet1 (eg i added headings, so i move my data to fr A1:A200 to A3:A203 (A1 to A2 rows will be assign for table heading).
which command lines manages this condition?
I had actually assumed a single row setting with the data starting on Row 2. The following changes should handle your new data start cell (I highlighted the changes I made from my last posted code in red so you can see what needed to be changed)...

Code:
Sub Update()[COLOR=#FF0000][/COLOR]
  Dim LastRow As Long, NextDay As Long
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  NextDay = Cells([COLOR=#FF0000][B]3[/B][/COLOR], Columns.Count).End(xlToLeft).Column + 1
  With Cells([COLOR=#FF0000][B]3[/B][/COLOR], NextDay).Resize(LastRow - [COLOR=#FF0000][B]2[/B][/COLOR])
    .Formula = "=IF(COUNTIF(Sheet2!$A$1:$A$200,$A2),""Y"",""N"")"
    .Value = .Value
    .Interior.ColorIndex = 3
    Application.ReplaceFormat.Clear
    Application.ReplaceFormat.Interior.ColorIndex = 4
    .Replace "Y", "", xlWhole, ReplaceFormat:=True
    Application.ReplaceFormat.Clear
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,191,577
Messages
5,987,399
Members
440,096
Latest member
yanaungmyint

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
Top