LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 63
Default Help needed with Macro designed to compare data...

Hello All

Some time ago I worked on a macro to compare data on one worksheet with that
in two other worksheets.

This macro was designed to check whether any records located in the
€śFiltered Data€ť worksheet already exist in either the €śOutstanding€ť or
€śComplete€ť worksheets. This was done by comparing a unique identifier (i.e.
the €śAGS Number€ť in Column A).

If the record doesnt already exist, then a copy of the record is placed in
the €śAdditions€ť worksheet.

If the record already exists in the €śOutstanding€ť worksheet, then a
comparison of the €śend date€ť field is made. If the end date is different, a
copy of the record is placed in the €śChanges€ť worksheet. If it isnt
different, then a copy is placed in the €śIgnored€ť worksheet.

Likewise, if the record already exists in the €śComplete€ť worksheet, then a
copy of it is placed in the €śIgnored€ť worksheet.

The same record cannot appear in both the €śOutstanding€ť and €śComplete€ť
worksheets.

In theory, then, by adding the total number of records located in the
€śIgnored€ť, €śAdditions€ť and €śChanges€ť worksheets, we should get the same
number of records located in the €śFiltered Data€ť worksheet.

This isnt happening and thats why I need your help! The following code was
written about six months ago with the help of other people and now Im at a
bit of a loss to find where the problem is:



Sub CompareData()

Sheets("Ignored").Select
Columns("A:Z").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Sheets("Additions").Select
Columns("A:Z").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Sheets("Changes").Select
Columns("A:Z").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select

Sh1RowCount = 1
Sh3RowCount = 1
Sh4RowCount = 1
Sh5RowCount = 1
With Sheets("Filtered Data")

Do While .Range("A" & Sh1RowCount) < ""

SearchItem = .Range("A" & Sh1RowCount)

With Sheets("Complete")
Set c = .Columns("A:A").Find(What:=SearchItem, _
LookIn:=xlValues)
End With

If c Is Nothing Then

With Sheets("Outstanding")
Set c = .Columns("A:A").Find(What:=SearchItem, _
LookIn:=xlValues)
End With

If c Is Nothing Then
.Rows(Sh1RowCount).Copy _
Destination:=Sheets("Additions").Rows(Sh3RowCount)
Sh3RowCount = Sh3RowCount + 1
Else
'compare end dates

If IsDate(.Range("K" & Sh1RowCount)) = True And
IsDate(c.Offset(0, 10)) = True Then
If CDate(.Range("K" & Sh1RowCount)) _
CDate(c.Offset(0, 10)) Then

.Rows(Sh1RowCount).Copy _
Destination:=Sheets("Changes").Rows(Sh4RowCount)
Sh4RowCount = Sh4RowCount + 1

End If
End If

End If

Else
.Rows(Sh1RowCount).Copy _
Destination:=Sheets("Ignored").Rows(Sh5RowCount)
Sh5RowCount = Sh5RowCount + 1

End If

Sh1RowCount = Sh1RowCount + 1
Loop

End With

MsgBox ("New data has been successfully compared to existing data.")

End Sub



If it helps, below are the headings associated with each column:

A AGS Number
B First Name
C Last Name
D User ID
E BSL
F Location
G Acting Grade
H Base Grade
I Reason
J Start Date
K End Date


I hope this makes sense€¦

Thanks for your help!

Joe.

--
If you can measure it, you can improve it!
 
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
Macro designed to send mails via Outlook : question on certificate Daniel[_18_] Excel Programming 2 October 24th 07 06:33 AM
macro needed to compare value and copy data underneath it to anoth Arain Excel Discussion (Misc queries) 1 April 17th 07 10:52 PM
Macro to compare two columns of data Odawg Excel Discussion (Misc queries) 1 October 12th 05 02:51 PM
Macro to compare two columns of data Odawg Excel Discussion (Misc queries) 0 October 12th 05 03:13 AM
script/macro that can compare data of two columns Saj Excel Programming 4 June 22nd 04 04:36 PM


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