Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default VB code required to compare name list

Hi all,

I would like some ideas of VB code that would take a name from cell A1 and
compare it with the name in B1.
If it is the same delete both A1 and B1 values, if it is different compare
against B2, delete A1 and B2 if name is same....etc etc

Columns A and B have a range of 15 rows

thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VB code required to compare name list

Option Explicit
Sub Testme()
dim iRow as long

'start from the bottom and work up
with activesheet
for irow = 15 to 1 step -1
if .cells(irow,"A").value = .cells(irow,"B").value then
.rows(irow).delete
end if
next irow
end with

End Sub


Anthony wrote:

Hi all,

I would like some ideas of VB code that would take a name from cell A1 and
compare it with the name in B1.
If it is the same delete both A1 and B1 values, if it is different compare
against B2, delete A1 and B2 if name is same....etc etc

Columns A and B have a range of 15 rows

thanks


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VB code required to compare name list

Delete or clear the cell?

Sub aA()
Dim cell As Range, res As Variant

For Each cell In Range("A1:A15")
res = Application.Match(cell, Range("B1:B15"), 0)
If Not IsError(res) Then
Cells(res, 2).ClearContents
cell.ClearContents
End If
Next

' if you want to delete then do

Range("A1:B15").SpecialCells(xlBlanks).Delete shift:=xlShiftUp


End Sub

--
Regards,
Tom Ogilvy


"Anthony" wrote in message
...
Hi all,

I would like some ideas of VB code that would take a name from cell A1 and
compare it with the name in B1.
If it is the same delete both A1 and B1 values, if it is different compare
against B2, delete A1 and B2 if name is same....etc etc

Columns A and B have a range of 15 rows

thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VB code required to compare name list

One of us read it wrong <g

--
Regards,
Tom Ogilvy


"Dave Peterson" wrote in message
...
Option Explicit
Sub Testme()
dim iRow as long

'start from the bottom and work up
with activesheet
for irow = 15 to 1 step -1
if .cells(irow,"A").value = .cells(irow,"B").value then
.rows(irow).delete
end if
next irow
end with

End Sub


Anthony wrote:

Hi all,

I would like some ideas of VB code that would take a name from cell A1
and
compare it with the name in B1.
If it is the same delete both A1 and B1 values, if it is different
compare
against B2, delete A1 and B2 if name is same....etc etc

Columns A and B have a range of 15 rows

thanks


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VB code required to compare name list

On Feb 6, 12:42 am, "Tom Ogilvy" wrote:
Delete or clear the cell?

Sub aA()
Dim cell As Range, res As Variant

For Each cell In Range("A1:A15")
res = Application.Match(cell, Range("B1:B15"), 0)
If Not IsError(res) Then
Cells(res, 2).ClearContents
cell.ClearContents
End If
Next

' if you want to delete then do

Range("A1:B15").SpecialCells(xlBlanks).Delete shift:=xlShiftUp

End Sub

--
Regards,
Tom Ogilvy

"Anthony" wrote in message

...

Hi all,


I would like some ideas of VB code that would take a name from cell A1 and
compare it with the name in B1.
If it is the same delete both A1 and B1 values, if it is different compare
against B2, delete A1 and B2 if name is same....etc etc


Columns A and B have a range of 15 rows


thanks


Hello,

I've tried your code and it works OK for deleting cells. That's very
useful to me. Thanks.

Does not seem to be working for deleting rows but I am probably wrong
since I am a complete newbie. Got error message 1004 "No cells were
found" even though there are rows with identical values. I probably
mistyped something below.

Best regards,
Laurent

Dim cell As Range, res As Variant

For Each cell In Range("A1:A15")
res = Application.Match(cell, Range("B1:B15"), 0)
If Not IsError(res) Then
Range("A1:B15").SpecialCells(xlBlanks).Delete shift:=xlShiftUp
End If
Next



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 275
Default VB code required to compare name list

Many thanks to you both for the excellent reply
Really appreciate your help
regards

"Tom Ogilvy" wrote:

Delete or clear the cell?

Sub aA()
Dim cell As Range, res As Variant

For Each cell In Range("A1:A15")
res = Application.Match(cell, Range("B1:B15"), 0)
If Not IsError(res) Then
Cells(res, 2).ClearContents
cell.ClearContents
End If
Next

' if you want to delete then do

Range("A1:B15").SpecialCells(xlBlanks).Delete shift:=xlShiftUp


End Sub

--
Regards,
Tom Ogilvy


"Anthony" wrote in message
...
Hi all,

I would like some ideas of VB code that would take a name from cell A1 and
compare it with the name in B1.
If it is the same delete both A1 and B1 values, if it is different compare
against B2, delete A1 and B2 if name is same....etc etc

Columns A and B have a range of 15 rows

thanks




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default VB code required to compare name list

the code wasn't written to delete rows. Maybe see Dave Peterson's post in
this thread.

--
Regards,
Tom Ogilvy


"lc61800" wrote:

On Feb 6, 12:42 am, "Tom Ogilvy" wrote:
Delete or clear the cell?

Sub aA()
Dim cell As Range, res As Variant

For Each cell In Range("A1:A15")
res = Application.Match(cell, Range("B1:B15"), 0)
If Not IsError(res) Then
Cells(res, 2).ClearContents
cell.ClearContents
End If
Next

' if you want to delete then do

Range("A1:B15").SpecialCells(xlBlanks).Delete shift:=xlShiftUp

End Sub

--
Regards,
Tom Ogilvy

"Anthony" wrote in message

...

Hi all,


I would like some ideas of VB code that would take a name from cell A1 and
compare it with the name in B1.
If it is the same delete both A1 and B1 values, if it is different compare
against B2, delete A1 and B2 if name is same....etc etc


Columns A and B have a range of 15 rows


thanks


Hello,

I've tried your code and it works OK for deleting cells. That's very
useful to me. Thanks.

Does not seem to be working for deleting rows but I am probably wrong
since I am a complete newbie. Got error message 1004 "No cells were
found" even though there are rows with identical values. I probably
mistyped something below.

Best regards,
Laurent

Dim cell As Range, res As Variant

For Each cell In Range("A1:A15")
res = Application.Match(cell, Range("B1:B15"), 0)
If Not IsError(res) Then
Range("A1:B15").SpecialCells(xlBlanks).Delete shift:=xlShiftUp
End If
Next


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VB code required to compare name list

Or one of us read more into it--and that's what the OP wanted (still a maybe on
that one, though!)

Tom Ogilvy wrote:

One of us read it wrong <g

--
Regards,
Tom Ogilvy

"Dave Peterson" wrote in message
...
Option Explicit
Sub Testme()
dim iRow as long

'start from the bottom and work up
with activesheet
for irow = 15 to 1 step -1
if .cells(irow,"A").value = .cells(irow,"B").value then
.rows(irow).delete
end if
next irow
end with

End Sub


Anthony wrote:

Hi all,

I would like some ideas of VB code that would take a name from cell A1
and
compare it with the name in B1.
If it is the same delete both A1 and B1 values, if it is different
compare
against B2, delete A1 and B2 if name is same....etc etc

Columns A and B have a range of 15 rows

thanks


--

Dave Peterson


--

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
Another VB Code Required TGV Excel Discussion (Misc queries) 7 February 7th 09 07:21 AM
VB code required to compare/delete data Anthony Excel Programming 3 February 4th 07 11:39 PM
VB code Required-------! Thyagaraj Excel Programming 1 July 17th 06 03:35 AM
Code help required peter.thompson[_33_] Excel Programming 4 January 10th 06 04:25 AM
Code required please Neal Excel Programming 2 January 24th 05 05:27 AM


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

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

About Us

"It's about Microsoft Excel"