PC Review


Reply
Thread Tools Rate Thread

Compare Problem

 
 
Stephen
Guest
Posts: n/a
 
      6th Mar 2008
Hi Folks,

i'm working on comparing column A in two workbooks and having the
differences reported back either to a sheet in workbook1 or a new workbook.
The code below runs without error but does not return any values and i know
there are differences which should be reported.

There is probably something wrong with my comparison but I'm not sure what
it is.

What i'd like to happen is for the macro to find values in column A that do
not appear in both workbooks and return the values for column A, B, and C.

Dim xlsFilePath As String
xlsFilePath = Application.GetOpenFilename
Application.Workbooks.Open xlsFilePath

MsgBox ("Path & File is " & xlsFilePath)
MsgBox ("File is " & ActiveWorkbook.Name)

Set mstrBook = Workbooks("NJ Pay Rate Check.xls")
Set mstrSheet = mstrBook.Sheets("Rate Check")

Set cmprBook = Workbooks(ActiveWorkbook.Name)
Set cmprSheet = cmprBook.Sheets("NJ Union Contract Raise Report")

Set newbk = Workbooks.Add
Set newbk_sht = newbk.Sheets("Sheet1")
NewbkRowCount = 1

With mstrSheet
LastRow = .Range("A200")
For RowCount = 6 To LastRow
If .Range("A" & RowCount) <> "" Then
empNum = .Range("A" & RowCount)
With cmprSheet
Set c = .Columns("A:A").Find(what:=empNum, _
LookIn:=xlValues, lookat:=xlWhole)
End With

If c Is Nothing Then
.Rows(RowCount).Copy _
Destination:=newbk_sht.Rows(NewbkRowCount)
NewbkRowCount = NewbkRowCount + 1
End If
End If
Next RowCount
End With

Any help is greatly appreciated.
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      6th Mar 2008
Just a guess but this is not going to work out for you

LastRow = .Range("A200")
is the same as
LastRow = .Range("A200").Value
which fills lastrow with whatever the value of cell A200 is...

You could change your code to
For RowCount = 6 To 200

Additionally you really should declare your variables...
--
HTH...

Jim Thomlinson


"Stephen" wrote:

> Hi Folks,
>
> i'm working on comparing column A in two workbooks and having the
> differences reported back either to a sheet in workbook1 or a new workbook.
> The code below runs without error but does not return any values and i know
> there are differences which should be reported.
>
> There is probably something wrong with my comparison but I'm not sure what
> it is.
>
> What i'd like to happen is for the macro to find values in column A that do
> not appear in both workbooks and return the values for column A, B, and C.
>
> Dim xlsFilePath As String
> xlsFilePath = Application.GetOpenFilename
> Application.Workbooks.Open xlsFilePath
>
> MsgBox ("Path & File is " & xlsFilePath)
> MsgBox ("File is " & ActiveWorkbook.Name)
>
> Set mstrBook = Workbooks("NJ Pay Rate Check.xls")
> Set mstrSheet = mstrBook.Sheets("Rate Check")
>
> Set cmprBook = Workbooks(ActiveWorkbook.Name)
> Set cmprSheet = cmprBook.Sheets("NJ Union Contract Raise Report")
>
> Set newbk = Workbooks.Add
> Set newbk_sht = newbk.Sheets("Sheet1")
> NewbkRowCount = 1
>
> With mstrSheet
> LastRow = .Range("A200")
> For RowCount = 6 To LastRow
> If .Range("A" & RowCount) <> "" Then
> empNum = .Range("A" & RowCount)
> With cmprSheet
> Set c = .Columns("A:A").Find(what:=empNum, _
> LookIn:=xlValues, lookat:=xlWhole)
> End With
>
> If c Is Nothing Then
> .Rows(RowCount).Copy _
> Destination:=newbk_sht.Rows(NewbkRowCount)
> NewbkRowCount = NewbkRowCount + 1
> End If
> End If
> Next RowCount
> End With
>
> Any help is greatly appreciated.

 
Reply With Quote
 
Stephen
Guest
Posts: n/a
 
      7th Mar 2008
Thanks for the reply but I already know this is not working for me, which is
why I'm turning to the experts for assistance.

I think I'm going about my solution the wrong way but I'm not familiar
enough the vba code to develop my solution on my own...

2 workbooks - 1 is MASTER the other is WEEKLY.
* I do know the name of the sheet in each that I want to compare, BUT I want
to compare column a values in each workbook/sheet and list any instance where
the column A value does not appear in both books and list the value from
column A, B, & C. it does not matter to me if the list is on a new workbook
or a specific sheet in the MASTER workbook.

So I think it's a two-way compare that I'm trying to accomplish.

Thank you to all with advise!

"Jim Thomlinson" wrote:

> Just a guess but this is not going to work out for you
>
> LastRow = .Range("A200")
> is the same as
> LastRow = .Range("A200").Value
> which fills lastrow with whatever the value of cell A200 is...
>
> You could change your code to
> For RowCount = 6 To 200
>
> Additionally you really should declare your variables...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Stephen" wrote:
>
> > Hi Folks,
> >
> > i'm working on comparing column A in two workbooks and having the
> > differences reported back either to a sheet in workbook1 or a new workbook.
> > The code below runs without error but does not return any values and i know
> > there are differences which should be reported.
> >
> > There is probably something wrong with my comparison but I'm not sure what
> > it is.
> >
> > What i'd like to happen is for the macro to find values in column A that do
> > not appear in both workbooks and return the values for column A, B, and C.
> >
> > Dim xlsFilePath As String
> > xlsFilePath = Application.GetOpenFilename
> > Application.Workbooks.Open xlsFilePath
> >
> > MsgBox ("Path & File is " & xlsFilePath)
> > MsgBox ("File is " & ActiveWorkbook.Name)
> >
> > Set mstrBook = Workbooks("NJ Pay Rate Check.xls")
> > Set mstrSheet = mstrBook.Sheets("Rate Check")
> >
> > Set cmprBook = Workbooks(ActiveWorkbook.Name)
> > Set cmprSheet = cmprBook.Sheets("NJ Union Contract Raise Report")
> >
> > Set newbk = Workbooks.Add
> > Set newbk_sht = newbk.Sheets("Sheet1")
> > NewbkRowCount = 1
> >
> > With mstrSheet
> > LastRow = .Range("A200")
> > For RowCount = 6 To LastRow
> > If .Range("A" & RowCount) <> "" Then
> > empNum = .Range("A" & RowCount)
> > With cmprSheet
> > Set c = .Columns("A:A").Find(what:=empNum, _
> > LookIn:=xlValues, lookat:=xlWhole)
> > End With
> >
> > If c Is Nothing Then
> > .Rows(RowCount).Copy _
> > Destination:=newbk_sht.Rows(NewbkRowCount)
> > NewbkRowCount = NewbkRowCount + 1
> > End If
> > End If
> > Next RowCount
> > End With
> >
> > Any help is greatly appreciated.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
schema compare problem gerry Microsoft ADO .NET 4 22nd May 2009 03:01 PM
Compare Problem with Header SnoozyFL Microsoft Word Document Management 0 12th Feb 2009 05:44 PM
Problem Compare Two File Giuseppe Microsoft VB .NET 5 25th Mar 2005 12:00 PM
SQL date compare problem Darrel Microsoft ASP .NET 5 9th Nov 2004 08:08 AM
string compare problem David zhu Microsoft C# .NET 19 12th Jul 2004 08:16 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:38 PM.