PC Review


Reply
Thread Tools Rate Thread

How can i compare particular columns of two worksheets and get a return

 
 
henson1182
Guest
Posts: n/a
 
      4th May 2007
Hi,

I am fairly new to VBA Programming. For my work i need to compare two
worksheets in same workbook. Worksheet A contains current months data and
work sheet B contains last months data. each month we have certain company's
that does not appear on last months worksheet and this month their products
increases in value and if there is an increase in some company's product
value we get that company's name and all the other info on our current months
worksheet.

What i need to do is:

Worksheet A:
Column is empty, column 2 contains the names of the company, Column three, 4,
5,6,7, conatin some other irrelevant data which i need on the file. Column 8
contains all the product names that have increase in value.

Worksheet B.
is layed out in same format.

I need to compare column 2 (company's name) from current month to last month.
if there is some company's name that appears on this months sheet, but does
not appear on last months sheet, in column 9 under heading "NEW" it should
say "Y" in current months worksheet. but if company appears on both
worksheets irrelevant to what row number they are in it should say "N" in
current months worksheet.

Any kind of VBA Coding help will be greatly appreciated.

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      4th May 2007
Hi henson1182 -

Here's a draft procedure for you to try. Note that it checks for empty
cells in column 2 of the 'current month list' and stamps such records with
"N/A". Modify to suit.

Sub henson1182()

Const toprow = 1 '<<header row number
Set wsa = Worksheets("SheetA") '<<current month sheet name
Set wsb = Worksheets("SheetB") '<<last month sheet name

lastrow = wsa.Cells(wsa.Rows.Count, 2).End(xlUp).Row

Set curRng = wsa.Range(wsa.Cells(toprow + 1, 2), wsa.Cells(lastrow, 2))

Application.ScreenUpdating = False
For Each itm In curRng
If itm <> "" Then
If Not wsb.Columns(2).Find(itm) Is Nothing Then
wsa.Cells(itm.Row, 9) = "Y"
Else
wsa.Cells(itm.Row, 9) = "N"
End If
Else
wsa.Cells(itm.Row, 9) = "N/A"
End If
Next 'itm
End Sub

----
Jay


"henson1182" wrote:

> Hi,
>
> I am fairly new to VBA Programming. For my work i need to compare two
> worksheets in same workbook. Worksheet A contains current months data and
> work sheet B contains last months data. each month we have certain company's
> that does not appear on last months worksheet and this month their products
> increases in value and if there is an increase in some company's product
> value we get that company's name and all the other info on our current months
> worksheet.
>
> What i need to do is:
>
> Worksheet A:
> Column is empty, column 2 contains the names of the company, Column three, 4,
> 5,6,7, conatin some other irrelevant data which i need on the file. Column 8
> contains all the product names that have increase in value.
>
> Worksheet B.
> is layed out in same format.
>
> I need to compare column 2 (company's name) from current month to last month.
> if there is some company's name that appears on this months sheet, but does
> not appear on last months sheet, in column 9 under heading "NEW" it should
> say "Y" in current months worksheet. but if company appears on both
> worksheets irrelevant to what row number they are in it should say "N" in
> current months worksheet.
>
> Any kind of VBA Coding help will be greatly appreciated.
>
>

 
Reply With Quote
 
henson1182 via OfficeKB.com
Guest
Posts: n/a
 
      9th May 2007
Thanks jay, it worked perfectly.

Is there any way, i can compare two columns from each worksheet. Like Company
column name and the product column. Company name can be repeated multiple
times with different products from the same company. and as i mentioned
earlier product are located in column 7. First 4 rows have general headers
and data start from row 5. I modified ear;ier code accordingly but i m having
trouble when i try to compare company's name and the product listed for that
row in column 7 to other sheet. Remember company names are not listed in same
rows on bothsheets. for example in sheet 1 xyz company is in row 20 with
product abc but in sheet two xyz is in row 19 with product abc. and then i
have multiple instance like xyz with product bcd in column 15 in sheet 1 and
in sheet 2 it is listed in column 10.


Anyone Please Help with this issue.

Thanks
Henson
Jay wrote:
>Hi henson1182 -
>
>Here's a draft procedure for you to try. Note that it checks for empty
>cells in column 2 of the 'current month list' and stamps such records with
>"N/A". Modify to suit.
>
>Sub henson1182()
>
>Const toprow = 1 '<<header row number
>Set wsa = Worksheets("SheetA") '<<current month sheet name
>Set wsb = Worksheets("SheetB") '<<last month sheet name
>
>lastrow = wsa.Cells(wsa.Rows.Count, 2).End(xlUp).Row
>
>Set curRng = wsa.Range(wsa.Cells(toprow + 1, 2), wsa.Cells(lastrow, 2))
>
>Application.ScreenUpdating = False
>For Each itm In curRng
> If itm <> "" Then
> If Not wsb.Columns(2).Find(itm) Is Nothing Then
> wsa.Cells(itm.Row, 9) = "Y"
> Else
> wsa.Cells(itm.Row, 9) = "N"
> End If
> Else
> wsa.Cells(itm.Row, 9) = "N/A"
> End If
>Next 'itm
>End Sub
>
>----
>Jay
>
>> Hi,
>>

>[quoted text clipped - 24 lines]
>>
>> Any kind of VBA Coding help will be greatly appreciated.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1

 
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
compare two worksheets and return a corresponding column Sai Krishna Microsoft Excel Misc 3 24th Jun 2008 09:16 PM
Compare 2 Worksheets and return differences in a third. =?Utf-8?B?VGhlQmlnU3RpZw==?= Microsoft Excel Worksheet Functions 4 1st Nov 2007 09:06 AM
Compare 2 columns - new worksheets =?Utf-8?B?RFRUT0RHRw==?= Microsoft Excel Worksheet Functions 1 29th Nov 2005 03:36 PM
how to compare columns in 4 worksheets =?Utf-8?B?RWxsZW4=?= Microsoft Excel Misc 0 26th Sep 2005 07:01 PM
compare columns of different worksheets =?Utf-8?B?Q2xhc3NpYw==?= Microsoft Excel Misc 2 2nd Dec 2004 10:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:25 PM.