ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Matching two sheets (https://www.excelbanter.com/excel-programming/302331-matching-two-sheets.html)

Marie

Matching two sheets
 
Sheet 1 has

District Amount
122 $5,000
122 $10,000

Sheet two has
Branch Type
55 VB
85 TB
44 TD
124 AB

The branch 55, 124, and 44 belong with district 122. The other numbers need to be deleted, the whole row. I only want the branches that match the district on the 1st sheet . I have code written that picks up the types on sheet two but it is a huge file. I want a code that will look at the district number (which I have 17 others) and match it to the right branch numbers. I have a cell that will always be the correct district number so I can refer to it but I can't get the rest to work. This is the code I have been trying to use but it deletes everything on the sheet. HELP!!!!!!!!

For Each Cell In Range("List") 'this range will always have the branch numbers on sheet one
Cell.Value = Cell.Value
D = Cell.Value
With Range("District") 'this is a seperat sheet I made with two columns.The first has the branch numbers and the second column with the district number - the range that is named is ONLY THE Branch number - is this what is wrong??
Set c = .Find(D, LookIn:=xlValues, LookAt:=xlWhole)
If Not c Is Nothing Then
tt = Range("districtnumber").Value 'this is the district # to use
ttt = c.Offset(0, 1).Value
If c.Offset(0, 1).Value = Range("DistrictNumber").Value Then
Offset(0, 1).Value
Else: Selection.EntireRow.Delete

End If
Else
'do nothing
End If
End With
Next Cell

End Sub


All times are GMT +1. The time now is 09:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com