Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
d4m d4m is offline
external usenet poster
 
Posts: 4
Default Delete row if value in another workbook

I have 2 workbooks. 1 has a list of PC's and other data. The 2nd one
has a list of PC's that if they exist in workbook1, then delete the row
in workbook1. Is there a way to do this in VBA?

Thanks for anyone who can help this newbie.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete row if value in another workbook

Option Explicit
Sub testme()

Dim rng1 As Range
Dim rng2 As Range
Dim res As Variant
Dim myCell As Range
Dim DelRng As Range

With Workbooks("book1.xls").Worksheets("sheet1")
Set rng1 = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Workbooks("book2.xls").Worksheets("sheet1")
Set rng2 = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In rng1.Cells
res = Application.Match(myCell.Value, rng2, 0)
If IsNumeric(res) Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(myCell, DelRng)
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.Select
'or (after testing!)
'DelRng.EntireRow.Delete
End If

End Sub



d4m wrote:

I have 2 workbooks. 1 has a list of PC's and other data. The 2nd one
has a list of PC's that if they exist in workbook1, then delete the row
in workbook1. Is there a way to do this in VBA?

Thanks for anyone who can help this newbie.


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
d4m d4m is offline
external usenet poster
 
Posts: 4
Default Delete row if value in another workbook

Works Great...Thank You very much!
Dave Peterson wrote:
Option Explicit
Sub testme()

Dim rng1 As Range
Dim rng2 As Range
Dim res As Variant
Dim myCell As Range
Dim DelRng As Range

With Workbooks("book1.xls").Worksheets("sheet1")
Set rng1 = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Workbooks("book2.xls").Worksheets("sheet1")
Set rng2 = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In rng1.Cells
res = Application.Match(myCell.Value, rng2, 0)
If IsNumeric(res) Then
If DelRng Is Nothing Then
Set DelRng = myCell
Else
Set DelRng = Union(myCell, DelRng)
End If
End If
Next myCell

If DelRng Is Nothing Then
'do nothing
Else
DelRng.Select
'or (after testing!)
'DelRng.EntireRow.Delete
End If

End Sub



d4m wrote:

I have 2 workbooks. 1 has a list of PC's and other data. The 2nd one
has a list of PC's that if they exist in workbook1, then delete the row
in workbook1. Is there a way to do this in VBA?

Thanks for anyone who can help this newbie.


--

Dave Peterson


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
How to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
how do you delete a workbook Bob Excel Discussion (Misc queries) 2 October 3rd 05 12:18 AM
Automatically Delete WorkBook 2 modules by using Workbook 1 module ddiicc Excel Programming 5 July 27th 05 12:53 PM
Delete a workbook sharman Excel Programming 4 June 23rd 05 08:07 PM
How do I delete a workbook after the vba has run? Patrick Excel Programming 1 January 28th 05 04:17 PM


All times are GMT +1. The time now is 08:13 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"