Then Rows(X).Delete command is Only deleting a column ??

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
When I run this, its deleting everything in column B - but not deleting its row. I want it to delete the row its on if what's in column B does not match what's in cell B1

Code:
Dim X As Long, lastrow As Long

lastrow = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row

For X = lastrow To 1 Step -1
    If Cells(X, 2).Value <> Range("B1").Value Then Rows(X).Delete

Next X

    ActiveSheet.Name = Range("$C$1").Value

Appreciate your time and help!!
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
try

Rows(X).EntireRow.Delete

or

Cells(x, 2).EntireRow.Delete
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,196
Members
449,072
Latest member
DW Draft

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