Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Tim M
 
Posts: n/a
Default Finding a cell match then deleting a row.

Greetings I did a search and found things close to what I want but I have not
been able to adapt them for my purpose successfully.

I have a sheet called 'Tables' with a one cell named range called 'Emphold'
An employees name gets copied into Emphold from a table of names elsewhere.

I have a sheet called 'Employee Database' with employee names in column A.

Via a macro I want to use the name that is in Emphold and search for an
exact match column A of the Employee Database sheet. If I find a match I
want to delete the entire row of the found name.

(This is to automate the deletion of an employee from the Employee Database
sheet.)
  #2   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student
 
Posts: n/a
Default Finding a cell match then deleting a row.

Hi Tim:

This code assumes that you have already defined the Name. It scans the used
rows and removes any rows with a match to the contents of Emphold:


Sub dropem()
Dim s As String
Dim r, emp As Range
Set emp = Range("Emphold")
s = emp.Value

Worksheets("Employee Database").Activate
Set r = ActiveSheet.UsedRange
j = r.Rows.Count + r.Row + 1

For i = j To 1 Step -1
If Cells(i, 1).Value = s Then
Rows(i).EntireRow.Delete
End If
Next
End Sub
--
Gary's Student


"Tim M" wrote:

Greetings I did a search and found things close to what I want but I have not
been able to adapt them for my purpose successfully.

I have a sheet called 'Tables' with a one cell named range called 'Emphold'
An employees name gets copied into Emphold from a table of names elsewhere.

I have a sheet called 'Employee Database' with employee names in column A.

Via a macro I want to use the name that is in Emphold and search for an
exact match column A of the Employee Database sheet. If I find a match I
want to delete the entire row of the found name.

(This is to automate the deletion of an employee from the Employee Database
sheet.)

  #3   Report Post  
Posted to microsoft.public.excel.misc
Tim M
 
Posts: n/a
Default Finding a cell match then deleting a row.

Thanks you very much, that worked out well. I just added a wee bit of code
to the front that actually copies the name to the hold cell and all is well.

"Gary''s Student" wrote:

Hi Tim:

This code assumes that you have already defined the Name. It scans the used
rows and removes any rows with a match to the contents of Emphold:


Sub dropem()
Dim s As String
Dim r, emp As Range
Set emp = Range("Emphold")
s = emp.Value

Worksheets("Employee Database").Activate
Set r = ActiveSheet.UsedRange
j = r.Rows.Count + r.Row + 1

For i = j To 1 Step -1
If Cells(i, 1).Value = s Then
Rows(i).EntireRow.Delete
End If
Next
End Sub
--
Gary's Student


"Tim M" wrote:

Greetings I did a search and found things close to what I want but I have not
been able to adapt them for my purpose successfully.

I have a sheet called 'Tables' with a one cell named range called 'Emphold'
An employees name gets copied into Emphold from a table of names elsewhere.

I have a sheet called 'Employee Database' with employee names in column A.

Via a macro I want to use the name that is in Emphold and search for an
exact match column A of the Employee Database sheet. If I find a match I
want to delete the entire row of the found name.

(This is to automate the deletion of an employee from the Employee Database
sheet.)

Reply
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
resetting last cell jagdish.eashwar Excel Discussion (Misc queries) 11 March 31st 06 02:06 AM
Format cell to match cells below in same column bakes1 Excel Discussion (Misc queries) 1 March 1st 06 07:01 PM
Instead of a negative number, I'd like to show zero... Dr. Darrell Excel Worksheet Functions 6 December 7th 05 08:21 PM
up to 7 functions? ALex Excel Worksheet Functions 10 April 12th 05 06:42 PM
GET.CELL Biff Excel Worksheet Functions 2 November 24th 04 07:16 PM


All times are GMT +1. The time now is 05:54 PM.

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"