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

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,273
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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

farmerscott

Well-known Member
Joined
Jan 26, 2013
Messages
818
Office Version
  1. 365
Platform
  1. Windows
try

Rows(X).EntireRow.Delete

or

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

Forum statistics

Threads
1,190,745
Messages
5,982,713
Members
439,791
Latest member
NwaTech_

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
Top