Create Loop to delete Value in tables if found in lookup - then delete lookup value

Paul1005

New Member
Joined
Dec 27, 2021
Messages
6
Office Version
  1. 2016
Platform
  1. Windows
I thought this would be easy but ive hit a brick wall and am struggling to get my head round what is needed.

I need to lookup the last value in the Sold Tab - Sold Table and then Search tables1,2 & 3 to see if value is found - If so delete this row.
Then return to the Sold Table and delete the variable just used.
I can't figure out how to loop it so it runs as many times as there are values in the sold table, so that all matching variables are deleted from Tables 1,2 & 3 - i.e if 3 variables run 3 times etc

This is as far as i have got so far, can anyone help please?

VBA Code:
Sub AAAA()

Dim Share As Range
Dim c As Range
Dim ws As Worksheet

Worksheets("Sold").Activate


Cells.Find(What:="Sold Share").End(xlDown).Select
If ActiveCell = "" Then Exit Sub
If ActiveCell <> "" Then Selection.Select
Set Share = ActiveCell

Worksheets("1").Activate
For Each c In Range("Table2")
    If c = Share Then c.EntireRow.Delete
    Next c

Worksheets("2").Activate
For Each c In Range("Table3")
    If c = Share Then c.EntireRow.Delete
    Next c

Worksheets("3").Activate
For Each c In Range("Table4")
    If c = Share Then c.EntireRow.Delete
    Next c

Worksheets("Sold").Activate
For Each c In Range("Sold")
    If c = Share Then c.EntireRow.Delete
     Next c

End

End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this:
Change the 4 in the macro to the column number you're looking for

Rich (BB code):
Sub AAAA()
  Dim sh As Worksheet
  Dim lo As ListObject
  Dim Share As Range, rng As Range, f As Range
  Dim s As Variant
 
  Set Share = Sheets("Sold").Cells.Find("Sold Share", , xlValues, xlWhole, , , False).End(xlDown)
  If Share.Value = "" Then Exit Sub
 
  For Each s In Array("1", "2", "3", "Sold")
    Set sh = Sheets(s)
    Set lo = sh.ListObjects(1)
    Set f = lo.ListColumns(4).Range.Find(Share.Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      lo.Range.AutoFilter Field:=4, Criteria1:="=" & Share.Value
      lo.Range.Offset(1).EntireRow.Delete
      lo.Range.AutoFilter
    End If
  Next
End Sub
 
Upvote 0
Try this:
Change the 4 in the macro to the column number you're looking for

Rich (BB code):
Sub AAAA()
  Dim sh As Worksheet
  Dim lo As ListObject
  Dim Share As Range, rng As Range, f As Range
  Dim s As Variant
 
  Set Share = Sheets("Sold").Cells.Find("Sold Share", , xlValues, xlWhole, , , False).End(xlDown)
  If Share.Value = "" Then Exit Sub
 
  For Each s In Array("1", "2", "3", "Sold")
    Set sh = Sheets(s)
    Set lo = sh.ListObjects(1)
    Set f = lo.ListColumns(4).Range.Find(Share.Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      lo.Range.AutoFilter Field:=4, Criteria1:="=" & Share.Value
      lo.Range.Offset(1).EntireRow.Delete
      lo.Range.AutoFilter
    End If
  Next
End Sub
Excellent thanks Dante
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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
Back
Top