Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2009, 01:26 PM
Authorized User
 
Join Date: Apr 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
Smile Comparing two different ranges

Hi Folks

I have two data ranges (old data and new data) with each range carrying mutilple columns. I have to figure out the best way to compare new data values with the original/old data. I could have done this easily if there was only one purchase order with many SKUs (Stock Keeping Units) by looping through the values. But in this case I have many POs and each PO has many SKUs.

I am not asking for a code solution, just the right logic to first look for PO in old data and compare all it's SKU's in the new data range with the old data and so on.

One thing that comes to my mind is to run primary and secondary loops. But I just doubt if there could be a better approach to get this done.

All of this being done because we have deleted may invoices and the only backup is our excel files and after re-entering the invoices again, we want to see if the quantities have been entered correctly.

Thanks
 
Old April 26th, 2009, 09:14 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

One option would be to create a temporary column in both the worksheets. This temp column might be the combination of Purchase Order and SKU Code something like PO_SKUCODE.

Assuming that this would be unique in both the new and old worksheets, you can loop through one of the workbook for this column and search the text in the other workbook in the newly created column

It hardly takes few seconds/minutes to create a new-column through code. You can delete the column once the process is done

Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old May 25th, 2009, 05:48 AM
Registered User
 
Join Date: May 2009
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default

use 2 for loop will seems like easier to do, but in consider of alot data, then this looping will be annoying because it will take a long time to loop through.
otherwise, u can try to use access query to get the data, and import it back to excel.
 
Old May 26th, 2009, 12:04 PM
Authorized User
 
Join Date: Jan 2009
Posts: 20
Thanks: 2
Thanked 0 Times in 0 Posts
Smile

You can also accomplish without even using code. Insert a new column that contains a unique identifier for the line item (PO-SKU). Something that would make it unique so that you could compare the new vs old. Do this for both new and old data. Then you could simply use the vlookup function against the unique identifier to return the value from the sheet that contains the old data. You can then insert a comparrison column at the end that will return true, false, or the difference, etc. Here is an example:

In this case the Key is the unique identifier for each item. Comparing the ShipQty from this month to last month...The difference is simply the following formula: IF(IF(ISNA(VLOOKUP(A2,$A$9:$F$13,1)),FALSE,TRUE)=T RUE,IF(VLOOKUP(A2,$A$9:$F$13,7)=E2,0,VLOOKUP(A2,$A $9:$F$13,7)-E2))

Column A = Key: 5551177-12333355 (Made up of PO#5551177 & SKU# of 12333355)
Column B= PO#
Column C = SKU#
Column D= OrderQty
Column E= ShipQty
Column F= QtyDue
Column G = Difference
Etc...

This formula simply says is the line item in last month's data? If so, then what was the Ship Qty last month and is it the same as the current month and if not then what is the difference.

Once you place your formula then you can copy and paste values so that excel doesn't keep recalculating when you save and so forth. Keeps it from slowing down.



Hope this helps some.
 
Old June 8th, 2009, 03:39 PM
Registered User
 
Join Date: Jun 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Red face I need help

I need help for complete my project so, when you have the time please see my Post : link a find button to the listbox





Similar Threads
Thread Thread Starter Forum Replies Last Post
puzzle for date ranges navjot C# 1 October 16th, 2008 02:21 PM
Date Ranges nbuckwheat Access 1 December 12th, 2005 12:45 PM
Copying ranges mtowle Excel VBA 2 November 2nd, 2005 06:35 AM
date ranges yuqlin BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 December 23rd, 2004 05:23 PM
Variable data Ranges dgarcia1128 Excel VBA 3 June 20th, 2003 02:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.