Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Macro for delete row with "vlookup"

I need a macro to find the numbers in column B of sheet "Backup", then look
at column B of "Raw data", if not found the same number delete entire row.
Like using vlookup if return #N/A then delete row, how to do so?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default Macro for delete row with "vlookup"

In my opinion this could be a good way:
write a code that will
1/ go thru column B of sheet Backup
2/ try to find each value in column B of Raw Data and if not succes
then
3/ delete entire row in Backup sheet
or ask someone who can write it for you.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Macro for delete row with "vlookup"

Hi,

Try this (test first!):

Sub CompareTwoColumns()

Dim rngA As Range
Dim rngB As Range

Set rngA = Worksheets("Backup").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)
Set rngB = Worksheets("Raw Data").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)

' In RngA but not in RngB

For i = rngA.Count To 1 Step -1 ' Loop through Backup numbers
If IsError(Application.Match(rngA(i).Value, rngB, 0)) Then
rngA(i).EntireRow.Delete ' Delete from Backup if not found in Raw Data
End If
Next

End Sub



"Angus" wrote:

I need a macro to find the numbers in column B of sheet "Backup", then look
at column B of "Raw data", if not found the same number delete entire row.
Like using vlookup if return #N/A then delete row, how to do so?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Macro for delete row with "vlookup"

Just a word of warning...

The unqualified cells(rows.count,"B") will refer to the activesheet. I think
I'd qualify those ranges.

with worksheets("backup")
Set rngA = .Range("B1:b" & .Cells(.Rows.Count, "B").End(xlUp).Row)
end with

with worksheets("raw data")
Set rngB = .Range("B1:b" & .Cells(.Rows.Count, "B").End(xlUp).Row)
end with

Another variation:

with worksheets("backup")
Set rngA = .Range("B1", .Cells(.Rows.Count, "B").end(xlup))
end with

with worksheets("raw data")
Set rngb = .Range("B1", .Cells(.Rows.Count, "B").end(xlup))
end with



Toppers wrote:

Hi,

Try this (test first!):

Sub CompareTwoColumns()

Dim rngA As Range
Dim rngB As Range

Set rngA = Worksheets("Backup").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)
Set rngB = Worksheets("Raw Data").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)

' In RngA but not in RngB

For i = rngA.Count To 1 Step -1 ' Loop through Backup numbers
If IsError(Application.Match(rngA(i).Value, rngB, 0)) Then
rngA(i).EntireRow.Delete ' Delete from Backup if not found in Raw Data
End If
Next

End Sub

"Angus" wrote:

I need a macro to find the numbers in column B of sheet "Backup", then look
at column B of "Raw data", if not found the same number delete entire row.
Like using vlookup if return #N/A then delete row, how to do so?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Macro for delete row with "vlookup"

Dave,
Thanks: I have fallen foul before of the error in not qualifying
the ranges (so I should know better!).


"Dave Peterson" wrote:

Just a word of warning...

The unqualified cells(rows.count,"B") will refer to the activesheet. I think
I'd qualify those ranges.

with worksheets("backup")
Set rngA = .Range("B1:b" & .Cells(.Rows.Count, "B").End(xlUp).Row)
end with

with worksheets("raw data")
Set rngB = .Range("B1:b" & .Cells(.Rows.Count, "B").End(xlUp).Row)
end with

Another variation:

with worksheets("backup")
Set rngA = .Range("B1", .Cells(.Rows.Count, "B").end(xlup))
end with

with worksheets("raw data")
Set rngb = .Range("B1", .Cells(.Rows.Count, "B").end(xlup))
end with



Toppers wrote:

Hi,

Try this (test first!):

Sub CompareTwoColumns()

Dim rngA As Range
Dim rngB As Range

Set rngA = Worksheets("Backup").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)
Set rngB = Worksheets("Raw Data").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)

' In RngA but not in RngB

For i = rngA.Count To 1 Step -1 ' Loop through Backup numbers
If IsError(Application.Match(rngA(i).Value, rngB, 0)) Then
rngA(i).EntireRow.Delete ' Delete from Backup if not found in Raw Data
End If
Next

End Sub

"Angus" wrote:

I need a macro to find the numbers in column B of sheet "Backup", then look
at column B of "Raw data", if not found the same number delete entire row.
Like using vlookup if return #N/A then delete row, how to do so?


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Macro for delete row with "vlookup"

It's perfect, thanks.

"Toppers" wrote:

Dave,
Thanks: I have fallen foul before of the error in not qualifying
the ranges (so I should know better!).


"Dave Peterson" wrote:

Just a word of warning...

The unqualified cells(rows.count,"B") will refer to the activesheet. I think
I'd qualify those ranges.

with worksheets("backup")
Set rngA = .Range("B1:b" & .Cells(.Rows.Count, "B").End(xlUp).Row)
end with

with worksheets("raw data")
Set rngB = .Range("B1:b" & .Cells(.Rows.Count, "B").End(xlUp).Row)
end with

Another variation:

with worksheets("backup")
Set rngA = .Range("B1", .Cells(.Rows.Count, "B").end(xlup))
end with

with worksheets("raw data")
Set rngb = .Range("B1", .Cells(.Rows.Count, "B").end(xlup))
end with



Toppers wrote:

Hi,

Try this (test first!):

Sub CompareTwoColumns()

Dim rngA As Range
Dim rngB As Range

Set rngA = Worksheets("Backup").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)
Set rngB = Worksheets("Raw Data").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)

' In RngA but not in RngB

For i = rngA.Count To 1 Step -1 ' Loop through Backup numbers
If IsError(Application.Match(rngA(i).Value, rngB, 0)) Then
rngA(i).EntireRow.Delete ' Delete from Backup if not found in Raw Data
End If
Next

End Sub

"Angus" wrote:

I need a macro to find the numbers in column B of sheet "Backup", then look
at column B of "Raw data", if not found the same number delete entire row.
Like using vlookup if return #N/A then delete row, how to do so?


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 81
Default Macro for delete row with "vlookup"

Dear experts,

it works perfect on my laptop (office 2003), but when i copy to my desktop
(office 2002), it comes with a error message "Compile error: Can't find
project or library" and highlight following line:

For i = rngA.Count To 1 Step -1 ' Loop through Backup numbers

What's wrong?

"Angus" wrote:

It's perfect, thanks.

"Toppers" wrote:

Dave,
Thanks: I have fallen foul before of the error in not qualifying
the ranges (so I should know better!).


"Dave Peterson" wrote:

Just a word of warning...

The unqualified cells(rows.count,"B") will refer to the activesheet. I think
I'd qualify those ranges.

with worksheets("backup")
Set rngA = .Range("B1:b" & .Cells(.Rows.Count, "B").End(xlUp).Row)
end with

with worksheets("raw data")
Set rngB = .Range("B1:b" & .Cells(.Rows.Count, "B").End(xlUp).Row)
end with

Another variation:

with worksheets("backup")
Set rngA = .Range("B1", .Cells(.Rows.Count, "B").end(xlup))
end with

with worksheets("raw data")
Set rngb = .Range("B1", .Cells(.Rows.Count, "B").end(xlup))
end with



Toppers wrote:

Hi,

Try this (test first!):

Sub CompareTwoColumns()

Dim rngA As Range
Dim rngB As Range

Set rngA = Worksheets("Backup").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)
Set rngB = Worksheets("Raw Data").Range("B1:b" & Cells(Rows.Count,
"B").End(xlUp).Row)

' In RngA but not in RngB

For i = rngA.Count To 1 Step -1 ' Loop through Backup numbers
If IsError(Application.Match(rngA(i).Value, rngB, 0)) Then
rngA(i).EntireRow.Delete ' Delete from Backup if not found in Raw Data
End If
Next

End Sub

"Angus" wrote:

I need a macro to find the numbers in column B of sheet "Backup", then look
at column B of "Raw data", if not found the same number delete entire row.
Like using vlookup if return #N/A then delete row, how to do so?

--

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
correct syntax for nesting "if", "and", and "vlookup"....if possib Christine Excel Worksheet Functions 4 January 2nd 09 10:43 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Excel "Move or Copy" and "Delete" sheet functions dsiama Excel Worksheet Functions 1 December 28th 07 01:57 PM
Macro to Replace/Delete Text Using "Watchword" List? PBJ Excel Discussion (Misc queries) 10 June 29th 07 09:50 PM
Adding "New" "Insert" "Delete" into a workbook to change from data 1 to data 2 etc Bob Reynolds[_2_] Excel Programming 0 March 4th 04 08:52 PM


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