Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Macro to compare columns and output the results

Hi,

I have another question.

I'm comparing two pairs of columns (Column D with E, Column F with G. The
data in these are vlookup-ed from other sheets) and putting down the
comparison results in Column H.

If Column D & E matches, Column F & G matches = Column H results: "ID
matches, number of files matches"
If Column D & E matches, Column F & G does NOT match = Column H results:
"ID matches, number of files does NOT match"
If Column D & E does NOT match, Column F & G match = Column H results: "ID
does NOT match, number of files matches"
If Column D & E does NOT match, Column F & G does NOT match = Column H
results: "ID does NOT match, number of files does NOT match"

If EITHER Column D & E is #N/A.... instead of "ID does not match" substitute
with "ID contains #N/A" in the results in Column H. Same for Column F & G, if
#N/A is present, substitute "Number of files does not match" with "Number of
files contains #N/A". So in Column H there will also be combinations like "ID
matches, number of files contains #N/A", "ID contains #N/A, number of files
does NOT match", and so on.

Using EXACT with much filtering/sorting can do the job, but it would be
great if this can be done with a macro :-)

TIA

Beth
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Macro to compare columns and output the results

Beth,

Sub HiLiteMatches()
Dim myR As Long

For myR = 2 To Cells(Rows.Count, 4).End(xlUp).Row
If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value)
Then
Range("H" & myR).Value = "ID contains #N/A, "
Else
If Range("D" & myR).Value = Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID matches, "
If Range("D" & myR).Value < Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID does NOT match, "
End If
If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value)
Then
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files contains #N/A, "
Else
If Range("F" & myR).Value = Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files matches, "
If Range("F" & myR).Value < Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files does NOT match, "
End If

Next myR

End Sub

HTH,
Bernie
MS Excel MVP



"Beth" wrote in message
...
Hi,

I have another question.

I'm comparing two pairs of columns (Column D with E, Column F with G. The
data in these are vlookup-ed from other sheets) and putting down the
comparison results in Column H.

If Column D & E matches, Column F & G matches = Column H results: "ID
matches, number of files matches"
If Column D & E matches, Column F & G does NOT match = Column H results:
"ID matches, number of files does NOT match"
If Column D & E does NOT match, Column F & G match = Column H results:
"ID
does NOT match, number of files matches"
If Column D & E does NOT match, Column F & G does NOT match = Column H
results: "ID does NOT match, number of files does NOT match"

If EITHER Column D & E is #N/A.... instead of "ID does not match"
substitute
with "ID contains #N/A" in the results in Column H. Same for Column F & G,
if
#N/A is present, substitute "Number of files does not match" with "Number
of
files contains #N/A". So in Column H there will also be combinations like
"ID
matches, number of files contains #N/A", "ID contains #N/A, number of
files
does NOT match", and so on.

Using EXACT with much filtering/sorting can do the job, but it would be
great if this can be done with a macro :-)

TIA

Beth



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Macro to compare columns and output the results

Sorry. The lines

If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value)
Then

and

If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value)
Then

both wrapped incorrectly - the Then should go on the same line as the first part...


HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Beth,

Sub HiLiteMatches()
Dim myR As Long

For myR = 2 To Cells(Rows.Count, 4).End(xlUp).Row
If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value) Then
Range("H" & myR).Value = "ID contains #N/A, "
Else
If Range("D" & myR).Value = Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID matches, "
If Range("D" & myR).Value < Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID does NOT match, "
End If
If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value) Then
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files contains #N/A, "
Else
If Range("F" & myR).Value = Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files matches, "
If Range("F" & myR).Value < Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files does NOT match, "
End If

Next myR

End Sub

HTH,
Bernie
MS Excel MVP



"Beth" wrote in message
...
Hi,

I have another question.

I'm comparing two pairs of columns (Column D with E, Column F with G. The
data in these are vlookup-ed from other sheets) and putting down the
comparison results in Column H.

If Column D & E matches, Column F & G matches = Column H results: "ID
matches, number of files matches"
If Column D & E matches, Column F & G does NOT match = Column H results:
"ID matches, number of files does NOT match"
If Column D & E does NOT match, Column F & G match = Column H results: "ID
does NOT match, number of files matches"
If Column D & E does NOT match, Column F & G does NOT match = Column H
results: "ID does NOT match, number of files does NOT match"

If EITHER Column D & E is #N/A.... instead of "ID does not match" substitute
with "ID contains #N/A" in the results in Column H. Same for Column F & G, if
#N/A is present, substitute "Number of files does not match" with "Number of
files contains #N/A". So in Column H there will also be combinations like "ID
matches, number of files contains #N/A", "ID contains #N/A, number of files
does NOT match", and so on.

Using EXACT with much filtering/sorting can do the job, but it would be
great if this can be done with a macro :-)

TIA

Beth





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Macro to compare columns and output the results

Hi Bernie,

Thanks! I figured out the wrapping and it worked like a charm :-)

I modified the macro to let it auto insert a new column for H
(.Columns("H").Insert). But how do I make it add the column title in H1 ?

TIA

Beth

"Bernie Deitrick" wrote:

Sorry. The lines

If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value)
Then

and

If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value)
Then

both wrapped incorrectly - the Then should go on the same line as the first part...


HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Beth,

Sub HiLiteMatches()
Dim myR As Long

For myR = 2 To Cells(Rows.Count, 4).End(xlUp).Row
If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value) Then
Range("H" & myR).Value = "ID contains #N/A, "
Else
If Range("D" & myR).Value = Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID matches, "
If Range("D" & myR).Value < Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID does NOT match, "
End If
If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value) Then
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files contains #N/A, "
Else
If Range("F" & myR).Value = Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files matches, "
If Range("F" & myR).Value < Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files does NOT match, "
End If

Next myR

End Sub

HTH,
Bernie
MS Excel MVP



"Beth" wrote in message
...
Hi,

I have another question.

I'm comparing two pairs of columns (Column D with E, Column F with G. The
data in these are vlookup-ed from other sheets) and putting down the
comparison results in Column H.

If Column D & E matches, Column F & G matches = Column H results: "ID
matches, number of files matches"
If Column D & E matches, Column F & G does NOT match = Column H results:
"ID matches, number of files does NOT match"
If Column D & E does NOT match, Column F & G match = Column H results: "ID
does NOT match, number of files matches"
If Column D & E does NOT match, Column F & G does NOT match = Column H
results: "ID does NOT match, number of files does NOT match"

If EITHER Column D & E is #N/A.... instead of "ID does not match" substitute
with "ID contains #N/A" in the results in Column H. Same for Column F & G, if
#N/A is present, substitute "Number of files does not match" with "Number of
files contains #N/A". So in Column H there will also be combinations like "ID
matches, number of files contains #N/A", "ID contains #N/A, number of files
does NOT match", and so on.

Using EXACT with much filtering/sorting can do the job, but it would be
great if this can be done with a macro :-)

TIA

Beth






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Macro to compare columns and output the results

Beth,

Great.

Immediately after your .Columns("H").Insert, use code like

Range("H1").Value = "Column Title for H"

HTH,
Bernie
MS Excel MVP


"Beth" wrote in message
...
Hi Bernie,

Thanks! I figured out the wrapping and it worked like a charm :-)

I modified the macro to let it auto insert a new column for H
(.Columns("H").Insert). But how do I make it add the column title in H1 ?

TIA

Beth

"Bernie Deitrick" wrote:

Sorry. The lines

If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value)
Then

and

If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value)
Then

both wrapped incorrectly - the Then should go on the same line as the first part...


HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Beth,

Sub HiLiteMatches()
Dim myR As Long

For myR = 2 To Cells(Rows.Count, 4).End(xlUp).Row
If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value) Then
Range("H" & myR).Value = "ID contains #N/A, "
Else
If Range("D" & myR).Value = Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID matches, "
If Range("D" & myR).Value < Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID does NOT match, "
End If
If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value) Then
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files contains #N/A, "
Else
If Range("F" & myR).Value = Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files matches, "
If Range("F" & myR).Value < Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files does NOT match, "
End If

Next myR

End Sub

HTH,
Bernie
MS Excel MVP



"Beth" wrote in message
...
Hi,

I have another question.

I'm comparing two pairs of columns (Column D with E, Column F with G. The
data in these are vlookup-ed from other sheets) and putting down the
comparison results in Column H.

If Column D & E matches, Column F & G matches = Column H results: "ID
matches, number of files matches"
If Column D & E matches, Column F & G does NOT match = Column H results:
"ID matches, number of files does NOT match"
If Column D & E does NOT match, Column F & G match = Column H results: "ID
does NOT match, number of files matches"
If Column D & E does NOT match, Column F & G does NOT match = Column H
results: "ID does NOT match, number of files does NOT match"

If EITHER Column D & E is #N/A.... instead of "ID does not match" substitute
with "ID contains #N/A" in the results in Column H. Same for Column F & G, if
#N/A is present, substitute "Number of files does not match" with "Number of
files contains #N/A". So in Column H there will also be combinations like "ID
matches, number of files contains #N/A", "ID contains #N/A, number of files
does NOT match", and so on.

Using EXACT with much filtering/sorting can do the job, but it would be
great if this can be done with a macro :-)

TIA

Beth









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default Macro to compare columns and output the results

Bernie,

Thanks, this works.

Beth

"Bernie Deitrick" wrote:

Beth,

Great.

Immediately after your .Columns("H").Insert, use code like

Range("H1").Value = "Column Title for H"

HTH,
Bernie
MS Excel MVP


"Beth" wrote in message
...
Hi Bernie,

Thanks! I figured out the wrapping and it worked like a charm :-)

I modified the macro to let it auto insert a new column for H
(.Columns("H").Insert). But how do I make it add the column title in H1 ?

TIA

Beth

"Bernie Deitrick" wrote:

Sorry. The lines

If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value)
Then

and

If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value)
Then

both wrapped incorrectly - the Then should go on the same line as the first part...


HTH,
Bernie
MS Excel MVP


"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
Beth,

Sub HiLiteMatches()
Dim myR As Long

For myR = 2 To Cells(Rows.Count, 4).End(xlUp).Row
If IsError(Range("D" & myR).Value) Or IsError(Range("E" & myR).Value) Then
Range("H" & myR).Value = "ID contains #N/A, "
Else
If Range("D" & myR).Value = Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID matches, "
If Range("D" & myR).Value < Range("E" & myR).Value Then _
Range("H" & myR).Value = "ID does NOT match, "
End If
If IsError(Range("F" & myR).Value) Or IsError(Range("G" & myR).Value) Then
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files contains #N/A, "
Else
If Range("F" & myR).Value = Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files matches, "
If Range("F" & myR).Value < Range("G" & myR).Value Then _
Range("H" & myR).Value = Range("H" & myR).Value & _
"number of files does NOT match, "
End If

Next myR

End Sub

HTH,
Bernie
MS Excel MVP



"Beth" wrote in message
...
Hi,

I have another question.

I'm comparing two pairs of columns (Column D with E, Column F with G. The
data in these are vlookup-ed from other sheets) and putting down the
comparison results in Column H.

If Column D & E matches, Column F & G matches = Column H results: "ID
matches, number of files matches"
If Column D & E matches, Column F & G does NOT match = Column H results:
"ID matches, number of files does NOT match"
If Column D & E does NOT match, Column F & G match = Column H results: "ID
does NOT match, number of files matches"
If Column D & E does NOT match, Column F & G does NOT match = Column H
results: "ID does NOT match, number of files does NOT match"

If EITHER Column D & E is #N/A.... instead of "ID does not match" substitute
with "ID contains #N/A" in the results in Column H. Same for Column F & G, if
#N/A is present, substitute "Number of files does not match" with "Number of
files contains #N/A". So in Column H there will also be combinations like "ID
matches, number of files contains #N/A", "ID contains #N/A, number of files
does NOT match", and so on.

Using EXACT with much filtering/sorting can do the job, but it would be
great if this can be done with a macro :-)

TIA

Beth








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
Lookup 2 columns of data, perform, match, output results John Excel Worksheet Functions 2 September 26th 08 11:30 AM
Compare 2 Columns, then output a list JohnHB Excel Programming 3 May 31st 07 09:46 PM
how to compare two columns and get a output from it [email protected] Excel Worksheet Functions 3 July 5th 06 08:19 AM
Compare 2 columns and output to a 3rd column jamaican jewel Excel Discussion (Misc queries) 1 March 22nd 06 09:26 PM
Macro to match output from 2 columns... [email protected] Excel Programming 5 July 16th 04 08:39 PM


All times are GMT +1. The time now is 12:19 PM.

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"