Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 90
Default MATCH/ LOOK UP

I have two sheets, In sheet 1 column A is full of numbers, I want to delete
all the lines in sheet 2 where column B does not match any number in Sheet 1
column A.

I am currently using the following code for another aapplication, if you
could modify this it would help me understand what I am doing a little better

Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DL"), Cells(Rows.Count, "DL").End(xlUp))

'Work backwards from bottom to top when deleting rows

With rng
For i = .Rows.Count To 1 Step -1
If Not Trim(.Cells(i)) = Trim(UserForm7.TextBox1) Then
.Cells(i).EntireRow.Delete
End If

Next i
End With

Thank you
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 199
Default MATCH/ LOOK UP

I'm not sure if this would work in your case, but try this one.

Sub Macrotest()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim rng As Range, r As Range, c As Range

Set sh1 = Worksheets("sheet1") '<<==Change to your name
Set sh2 = Worksheets("sheet2") '<<==Change to your name
Set rng1 = Range(sh1.Cells(1, "A"), _
sh1.Cells(Rows.Count, "A").End(xlUp))
Set rng2 = Range(sh2.Cells(1, "B"), _
sh2.Cells(Rows.Count, "B").End(xlUp))

On Error Resume Next
For Each r In rng1
Set c = rng2.Find(r.Value, LookIn:=xlValues, _
lookat:=xlWhole, MatchCase:=False)
Do While (Not c Is Nothing)
c.EntireRow.Delete
Set c = rng2.Find(r.Value, LookIn:=xlValues, _
lookat:=xlWhole, MatchCase:=False)
Loop
Next
End Sub

Keiji

Miree wrote:
I have two sheets, In sheet 1 column A is full of numbers, I want to delete
all the lines in sheet 2 where column B does not match any number in Sheet 1
column A.

I am currently using the following code for another aapplication, if you
could modify this it would help me understand what I am doing a little better

Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DL"), Cells(Rows.Count, "DL").End(xlUp))

'Work backwards from bottom to top when deleting rows

With rng
For i = .Rows.Count To 1 Step -1
If Not Trim(.Cells(i)) = Trim(UserForm7.TextBox1) Then
.Cells(i).EntireRow.Delete
End If

Next i
End With

Thank you

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default MATCH/ LOOK UP

Sub test()
Dim rng As Range
Dim i As Long
Dim rngend As Long
Worksheets("Sheet2").Activate
rngend = Cells(Rows.Count, "B").End(xlUp).Row
Set rng = ActiveSheet.Range(Cells(1, "B"), Cells(rngend, "B"))

'Work backwards from bottom to top when deleting rows

With rng
For i = rngend To 1 Step -1
hit = 0
On Error Resume Next
hit = WorksheetFunction.Match(.Cells(i),
Worksheets("Sheet1").Columns("A"), 0)
On Error GoTo 0
If hit = 0 Then .Cells(i).EntireRow.Delete
Next i
End With

End Sub

Regards,
Stefi

€˛Miree€¯ ezt Ć*rta:

I have two sheets, In sheet 1 column A is full of numbers, I want to delete
all the lines in sheet 2 where column B does not match any number in Sheet 1
column A.

I am currently using the following code for another aapplication, if you
could modify this it would help me understand what I am doing a little better

Dim rng As Range
Dim i As Long

Set rng = ActiveSheet.Range(Cells(1, "DL"), Cells(Rows.Count, "DL").End(xlUp))

'Work backwards from bottom to top when deleting rows

With rng
For i = .Rows.Count To 1 Step -1
If Not Trim(.Cells(i)) = Trim(UserForm7.TextBox1) Then
.Cells(i).EntireRow.Delete
End If

Next i
End With

Thank you

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lookup Formula: Return 1st match, then 2nd match, then 3rd match Scott Excel Discussion (Misc queries) 4 December 11th 09 05:50 AM
index(match) Wind Uplift Calculations (match four conditions) JMeier Excel Worksheet Functions 8 August 1st 08 01:45 AM
MATCH Multiple Criteria & Return Previous / Penultimate Match Sam via OfficeKB.com Excel Worksheet Functions 27 October 6th 07 01:39 AM
Lookup? Match? pulling rows from one spreadsheet to match a text f cjax Excel Worksheet Functions 3 July 21st 06 02:51 PM
searching a list box for a filename match...and highlighting the match suee[_4_] Excel Programming 1 April 13th 04 02:56 AM


All times are GMT +1. The time now is 02:46 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"