LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default VLOOKUP and delete row if found

I have a spreadsheet in which payroll clerks enter data for hundreds of
employees. One of the fields entered is the Oracle number of the
employee. I want to check a range in the sheet "Upload Data" for the
existence of the Oracle number. If the Oracle number is there, I want
to delete the row. There may be multiple rows with the Oracle number,
so I must check the entire range.

I am using a function called GetRealLastCell to determine the lookup
range.

Following is the code. I am stil in the developmental stage as I am
not able to get a match on the Oracle number even when it's there. I
believe there's something wrong with my vlookup statement. Once I find
a matching row, what syntax do I use to delete that row?

Since I have to delete all rows with the Oracle number, is it better to
loop through the range and check for the existence of the Oracle number
and delete the row if there's a match?

Private Sub Check_For_Existing_Oracle_No_Click()
Dim rng As Range
Dim Test As Variant
Sheets("Upload Data").Select
Set rng = GetRealLastCell(ActiveSheet)
LookupRange = ("$C$2:" + rng.Address)
Test = Application.VLookup(Oracle_No, LookupRange, 0, False)
If IsError(Test) Then
MsgBox "It wasn't found"
Else
MsgBox "it was found"
End If
End Sub

Function GetRealLastCell(sh As Worksheet) As Range
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByRows, xlPrevious).Row
RealLastColumn = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByColumns,
xlPrevious).Column
Set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
End Function

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete a row if strong NOT found.... JayKay100 Excel Discussion (Misc queries) 9 November 23rd 08 06:20 AM
Delete Rows when Blanks are found in Column A:A ddiicc Excel Programming 4 August 4th 05 10:46 AM
Further help on delete criteria found rjamison Excel Programming 0 June 14th 05 12:14 AM
Further help on delete criteria found rjamison Excel Programming 0 June 14th 05 12:14 AM
Further help on delete criteria found Tempy Excel Programming 6 April 27th 05 08:52 AM


All times are GMT +1. The time now is 07:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"