how do i keep it all rows from deleting

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
140
Office Version
  1. 365
  2. 2019
Sorry if this has been answered before I searched and did find some similarities but nothing quite the same and wasn't able to use what i found to fix my problem. I get a spreadsheet at the start of each month that has employee turnover by manager and department problem is that i want to be able to keep the rows equal to Account Management located in column F. The code below deletes everything in column F but it deletes the Account Management as well (it deletes everything else first and then Account Management last) It also deletes the column headers located in row three Any help would be greatly appreciated.

Sub ACCT_MGMT()
'


'
Dim lr As Long





For lr = Range("f" & Rows.Count).End(xlUp).Row To 2 Step -1
If Range("f" & lr).Value <> "Account Management" Then
Rows(lr).EntireRow.Delete
End If
Next lr




'
End Sub
 

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.
Hello,

Your macro is fine ...

Code:
Sub ACCT_MGMT()
Dim lr As Long
For lr = Range("f" & Rows.Count).End(xlUp).Row To 2 Step -1
  If Range("f" & lr).Value <> "Account Management" Then
    Rows(lr).EntireRow.Delete
  End If
Next lr
End Sub

Just make sure the spelling of Account Management is exactly identical.... both in your sheet and in your macro ..

HTH
 
Last edited:
Upvote 0
Along with what James006 has said you'll need to make this change, to prevent the header row being deleted.
Code:
For lr = Range("f" & Rows.Count).End(xlUp).Row To [COLOR=#ff0000]4[/COLOR] Step -1
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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