DMFisher

New Member
Joined
Apr 22, 2016
Messages
35
Hi,

Is it possible to have a macro that deletes data from a table?

e.g - If cell I10 (Sheet2) matches data in a table on Sheet1 then delete the row that the data is stored in on Sheet1
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
something along the lines of

Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "a").End(xlUp).Row
For i = Lastrow To 1 Step -1
If Cells(i, 1).Value = Sheets("Sheet2").Range("i10").Value Then
Rows(i).Delete
End If
Next
 
Upvote 0
Hi Steve,

If I wanted the macro to search for the data typed in I10 (on sheet 2) in column B on sheet 1, (Then delete that row) what would this code look like?
 
Upvote 0
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "b").End(xlUp).Row
For i = Lastrow To 1 Step -1
If Cells(i, 2).Value = Sheets("Sheet2").Range("i10").Value Then
Rows(i).Delete
End If
Next
 
Upvote 0
This doesn't seem to work. I dont think I explained it very well previously + I had the wrong cell

The formula basically needs to do the following:

If cell D9 on Sheet1 matches a cell in Column B on Sheet2, then delete the row that contains that data from sheet2
 
Upvote 0
sheets("Sheet2").activate
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "b").End(xlUp).Row
For i = Lastrow To 1 Step -1
If Cells(i, 2).Value = Sheets("Sheet1").Range("d9").Value Then
Rows(i).Delete
End If
Next
 
Upvote 0
This macro has worked but when I use it on a different sheet (And change the sheet numbers in the macro) the 6th row is highlighted as incorrect when I try to run it.:
If Cells(i, 2).Value = Sheets("Sheet3").Range("d9").Value Then
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,561
Members
449,089
Latest member
Motoracer88

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