Computing.Net > Forums > Office Software > Excel - Formula Based Row Deletion

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Excel - Formula Based Row Deletion

Reply to Message Icon

Name: mnnewbie
Date: April 21, 2009 at 10:23:55 Pacific
OS: Windows XP/Excel2003
Subcategory: Microsoft Office
Comment:

Hello!
I have a, Excel workbook in which there are 2 spreadsheets; sheet1 contains a large amount of employee data and sheet2 contains names & project teams.

I currently use formula '=VLOOKUP(H4, Sheet2!A:B, 2, FALSE)' on Sheet1(columnA) to map project teams (from Sheet2, columnB) based by employee names from Sheet1, columnH.

I need to go 1 step further and delete any rows where a project team was not returned (now displaying #N/A) on sheet1.

I've tried to modify other provided examples, but with no success - just a bunch of errors.

Can anyone help?

Thanks!!



Sponsored Link
Ads by Google

Response Number 1
Name: DerbyDad03
Date: April 21, 2009 at 10:53:00 Pacific
Reply:

re: Your subject line Formula Based Row Deletion

I assume you are aware that you can't actually delete a Row via a "formula". You can however do it with VBA.

re: I've tried to modify other provided examples

What examples have you tried?


0

Response Number 2
Name: mnnewbie
Date: April 21, 2009 at 12:32:04 Pacific
Reply:

I do know that, but I'm new to VB.

Basically I'm trying to delete any rows that did not have a project team returned into ColumnA as a result of the VLOOKUP function.

Here's the one I tried using from online and tweaking it; my issue is that I use vlookup to get the project team into sheet1 (column A)based on a table with the individual's name & project team from sheet2.

In using the sample below, it expects actual data and not formulas in the cell to determine the criteria to delete.

Sub DeleteRows()
Dim strToDelete As String
Dim rngSrc As Range
Dim NumRows As Integer
Dim ThisRow As Integer
Dim ThatRow As Integer
Dim ThisCol As Integer
Dim J As Integer
Dim DeletedRows As Integer

strToDelete = InputBox("Value to Trigger Delete?", "Delete Rows")
Set rngSrc = ActiveSheet.Range(ActiveWindow.Selection.Address)

NumRows = rngSrc.Rows.Count
ThisRow = rngSrc.Row
ThatRow = ThisRow + NumRows - 1
ThisCol = rngSrc.Column

For J = ThatRow To ThisRow Step -1
If Cells(J, ThisCol) = strToDelete Then
Rows(J).Select
Selection.Delete Shift:=xlUp
DeletedRows = DeletedRows + 1
End If
Next J
MsgBox "Number of deleted rows: " & DeletedRows
End Sub

Any suggestions? Or could you point me in the right direction? (I'd like to understand so I can learn from this - I'm new to coding...)


0

Response Number 3
Name: DerbyDad03
Date: April 21, 2009 at 13:15:28 Pacific
Reply:

If I wanted to delete rows that contained #N/A in Column A, and I wasn't concerned about any other error showing up in that cell, I'd use something like this:

Sub Del_NA()
'Find last row with data in Column A
lastRow = Range("A" & Rows.Count).End(xlUp).Row
'Start at bottom and delete rows with errors
 For myNA = lastRow To 1 Step -1
  If IsError(Cells(myNA, 1)) Then _
   Cells(myNA, 1).EntireRow.Delete
 Next
End Sub


0

Response Number 4
Name: mnnewbie
Date: April 21, 2009 at 13:57:51 Pacific
Reply:

Huh -simple...I like it!

I'm going to run it and I'll let you know how it goes. Thanks for your help!!


0

Response Number 5
Name: DerbyDad03
Date: April 21, 2009 at 19:44:17 Pacific
Reply:

Of course, you are going to run it on backup copy of your file, right?


0

Related Posts

See More



Response Number 6
Name: mnnewbie
Date: April 23, 2009 at 06:17:09 Pacific
Reply:

Of course - I run all of my testing on a local copy!!

Thanks for your help - it worked perfectly!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Outlook Free/Busy Not Sho... Excel custom tab order



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Excel - Formula Based Row Deletion

Excel Formula Help - How to Delete a Row www.computing.net/answers/office/excel-formula-help-how-to-delete-a-row/9347.html

Excell Formula www.computing.net/answers/office/excell-formula/7618.html

Copy formula based on used cell www.computing.net/answers/office/copy-formula-based-on-used-cell/7635.html