Flux rss
Search : in
By : Relevance Date Username
Statut : Solved

Compare cell a1 to entire A col in sheet2

Bill, on Thursday August 28, 2008 05:49:35 PM
Hello,

I have been trying to compare sheet1 A2 to sheet2 A2 through A500 and if it exists somewhere in sheet2's a col then copy that entire row to a new sheet.

I have experimented with many bits of macro code from others but so far no real success.


Figuring out how to say that in code is a bit difficult for me. I'm struggling to get the hang of this.

Maybe...

sub compare()
Dim LastRow_1 As Integer
Dim LastCol_1 As Integer
Dim Data_1 As range
Dim LastRow_2 As Integer
Dim LastCol_2 As Integer
Dim Data_2 As range

Dim Sh_1 As Worksheet
Dim Sh_2 As Worksheet

Dim X As Long
Dim Y As Long
Dim C_1 As range
Dim C_2 As range

Set Sh_1 = ActiveWorkbook.Sheets("Master")
Set Sh_2 = ActiveWorkbook.Sheets("Inventory")

LastRow_1 = Sh_1.range("A5000").End(xlUp).Row
LastCol_1 = Sh_1.range("A5000").End(xlToLeft).Column
Set Data_1 = Sh_1.range("A2").Resize(LastRow_1, LastCol_1)

LastRow_2 = Sh_2.range("A5000").End(xlUp).Row
LastCol_2 = Sh_2.range("A5000").End(xlToLeft).Column
Set Data_2 = Sh_2.range("A2").Resize(LastRow_2, LastCol_2)

For Each C_1 In Data_1
For Each C_2 In Data_2
If C_2 = C_1 Then
'found a cell on sheet2 that matched cell in sheet1
'now do what you need to do
Data_2.EntireRow.Copy Destination:=Worksheets("New_Master").range("A5000").End(xlUp).Offset(1, 0)

End If


Next C_2
Next C_1
end sub


When I run this it just copies everything to the sheet called New_Master, including the non-matches.

What am I missing? It has to be obvious, that's usually the case. ;-)

Thanks,

Bill
Configuration: Windows XP
Firefox 2.0.0.11
Reply to Bill  Report this message to moderators Go to last message

1


  • 1
    This message seems useful, vote!
  • Ce message ne vous semble pas utile, votez !
  • Report this message to moderators
Ivan-hoe, on Tuesday September 2, 2008 08:55:00 AM
Hello Bill,
when you write
Data_2.EntireRow.Copy

you copy the whole range "Data_2", which corresponds to the column A of the sheet "Inventory"
If you want to copy only the rows in Data_2 that match with Data_1, do write
C_2.EntireRow.Copy 

I hope it helps
Ivan
Reply to Ivan-hoe

2


  • This message seems useful, vote!
  • Report this message to moderators
 bill, on Tuesday September 2, 2008 12:48:04 PM
Ivan,

COOL! Thanks!

Bill
Reply to bill

Results for

Spreadsheets - Cell Selection Spreadsheets are powerful tools for working with data. However, to work with data, it is necessary to have tools to rapidly choose the required cells. An entire line can be chosen by clicking directly on the line header: It is also possible to choose... en.kioskea.net/tableur/tabcellselect-1.php3
From sheet 2 cell find sheet1 name then value Hello, I am using Excel 2003, Windowx XP Professional, and Internet Explorer 7 In one Excel 3003 example workbook sheet1 contains data copied in from Internet Explorer 7 that keeps changing position on the sheet. From a cell, EG C5, in sheet2 I want... en.kioskea.net/forum/affich-27953-from-sheet-2-cell-find-sheet1-name-then-value
Changin format of date in excel Hello, I have an excel sheet which has lots of cells in a column with the date format as - day month date time year & I wish to convert that to dd/mm/yy. How can I do that, pls help. eg - I need to convert "sat Jun 29 00:00:00 PST 1996" to "29/06/96".... en.kioskea.net/forum/affich-28689-changin-format-of-date-in-excel

Results for

Excel tips : How to insert date In an Excel cellExcel tips : How to insert date In an Excel cell Below are some tips on how to insert date and time in an excel cell for a specific purpose:- To insert current date, press “CTRLâ€+ “;†in the chosen cell. To insert current... en.kioskea.net/faq/sujet-313-excel-tips-how-to-insert-date-in-an-excel-cell

Results for

Updation of worksheet cell valueHello, I have a worksheet named "Sheet1". In the cells P1 to P5, I have hardcoded the values 1,2,3,4 and 5. These values are taken as drop down in cell "A1" (Data->Validation->List). I have a worksheet named "Sheet2", whose contents are the same as... en.kioskea.net/forum/affich-30577-updation-of-worksheet-cell-value
Excel macro help needed to name rangesHello, I have a 10 column x 500 row spreadsheet A1:J500 I would like to name ranges as follows: Range A1:J1 should be named with the content of cell A1, range A2:J2 should be named with the content of cell A2, etc, etc. Can anyone help me with a macro... en.kioskea.net/forum/affich-21552-excel-macro-help-needed-to-name-ranges
Little problem with excel sheetHello I have a table that contains a row with many numbers. I want to look at each individual cell in that column and compare its value to a range of values. If the value in the cell matches the range, I want to add a percentage to the number and... en.kioskea.net/forum/affich-5591-little-problem-with-excel-sheet

Results for

Download Driver Samsung CLP-510 Color LaserThe printer Samsung CLP-510N is a laser printer. The resolution of the scanner is of 1200 x on 1200 dpi. It is entirely compatible with PC systems, Unix and Mac. Its speed of impression in black and white is 25 ppm and in colour 6ppm. This model is... en.kioskea.net/telecharger/telecharger-934-driver-samsung-clp-510-color-laser
Download Driver Ricoh Aficio SP C811DNThe printer Ricoh Aficio SP C811DN is a printer laser. It inserts one processor 866 MHz. His maximum resolution is of 1800 dpi. It is entirely compatible with PC systems, Unix and Mac. His speed of impression in black and white and in color is 40... en.kioskea.net/telecharger/telecharger-935-driver-ricoh-aficio-sp-c811dn
Download Driver Ricoh Aficio GX 7000 RPCS Raster PrinterThe printer Ricoh Aficio GX 7000 is an ink jet printer of ink. Its maximum resolution is of 3600 dpi. It is entirely compatible with the systems PC, Unix and Mac. Its speed d' impression in black and white and color is of 29 ppm. This model is... en.kioskea.net/telecharger/telecharger-964-driver-ricoh-aficio-gx-7000-rpcs-raster-printer

Results for

High-tech shopping carts to be deployed in SingaporeA worker pushs shopping carts past the entrance of British superstore Tesco in Bangkok. Dubbed "MediaCarts", the carts will be deployed in a pilot project for the first time in Asia at a new branch of Singapore's Cold Storage supermarket chain... en.kioskea.net/actualites/high-tech-shopping-carts-to-be-deployed-in-singapore-10159-actualite.php3
Sony unveils turntable to put vinyl on computerThe entrance of Swedish-Japanese mobile handset maker Sony Ericsson's factory in Ribeauville, eastern France. Sony Corp. said Wednesday it will soon sell a record deck that plugs into a computer to let vinyl collectors convert their analogue... en.kioskea.net/actualites/sony-unveils-turntable-to-put-vinyl-on-computer-10199-actualite.php3

Results for

Worksheet - Cells A "cell" is the intersection between a line (horizontal) and a column (vertical) on a worksheet. Thus, the name of the line combined with the name of the column gives the cell's coordinates (the term address is sometimes also used). Coordinates... en.kioskea.net/tableur/tabcellule.php3
Spreadsheets - Worksheets Spreadsheets display data and formulas in a table form (lines and columns) called a worksheet. A worksheet is made of lines (numbered with numbers) and of columns (numbered with letters). The intersection of a line and a column is called a cell. A... en.kioskea.net/tableur/tabfeuille.php3
Project management - The methodology of running a project Meetings are a way of sharing, within a group of individuals, the same level of knowledge of a subject or a problem and of making decisions collectively. Additionally, decisions made collectively, with representatives of the various entities... en.kioskea.net/projet/conduite-reunion.php3