Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 01-28-2004, 11:26 PM   #1
Member (6 bit)
 
Join Date: May 2000
Posts: 49
Question Comparing more data!

Maybe someone can help with this.

I have data that I automatically download with Excel that contains item numbers, price and quantities, among other things in other columns. I have another spreadsheet that contains my current prices and item numbers. The spreadsheet that I download contains many more items than I currently have on my spreadsheet. If I had the new items I downloaded located in Sheet 1 and my current items in Sheet 2, howcould I (with a macro) compare the two and display only the data that has changed on a different sheet (ignoring all items that I currently do not have on my spreadsheet)? Here's an example:

On my new spreadsheet (the one that is updated daily) an item is listed with an item number "100" and a price of $25.
My current spreadsheet has item number "100" listed at a price of $17. When I run the macro, I would like it to list (on another sheet) the item number "100" and the new price of "$25" All other data will be ignored if I do not have it listed on my spreadsheet.

Here's one thing that I think made it difficult. One spreadsheet could contain 3500+ items (the one I download) and my spreadsheet containing my current items would probably be less than 500.

Can anyone help? If needed, I can list more details.

TIA!
merlin63 is offline   Reply With Quote
Old 01-29-2004, 08:13 AM   #2
sym
Member (7 bit)
 
Join Date: Nov 2001
Location: Rochester, NY
Posts: 87
The forum doesn't seem to want to keep indented code, so it is a bit hard to read.


Public Sub CompareToDownload()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim curWBK As Workbook
Dim downloadWBK As Workbook
Dim curSheet As Worksheet
Dim downloadSheet As Worksheet
Dim compareSheet As Worksheet
Dim curItemNum As String
Dim curItemPrice As Double

Application.ScreenUpdating = False

' get references to the workbooks
Set curWBK = Workbooks("ItemNum_Price.xls")
Set downloadWBK = Workbooks("Download_Items.xls")

' get references to the relevant sheets
Set curSheet = curWBK.Sheets("Sheet1")
Set downloadSheet = downloadWBK.Sheets("Sheet1")

' this sheet is the page that the comparisons are displayed on
On Error Resume Next
Set compareSheet = curWBK.Sheets("CompareSheet")
If compareSheet Is Nothing Then
' if it doesn'n exist, create it
Set compareSheet = curWBK.Sheets.Add()
compareSheet.Name = "CompareSheet"
Else
' if it does exist, clear it of data
compareSheet.Cells.Delete
End If
On Error GoTo 0
compareSheet.Range("A1").Value = "Item #"
compareSheet.Range("B1").Value = "New Price"
compareSheet.Range("C1").Value = "Old Price"

k = 2
For i = 2 To curSheet.UsedRange.Rows.Count
curItemNum = curSheet.Range("A" & i).Value
curItemPrice = curSheet.Range("B" & i).Value
blnFound = False
For j = 2 To downloadSheet.UsedRange.Rows.Count
If downloadSheet.Range("A" & j).Value = curItemNum Then
If downloadSheet.Range("B" & j).Value <> curItemPrice Then
compareSheet.Range("A" & k).Value = curItemNum
compareSheet.Range("B" & k).Value = curItemPrice
compareSheet.Range("C" & k).Value = downloadSheet.Range("B" & j).Value
k = k + 1
End If
j = downloadSheet.UsedRange.Rows.Count
End If
Next j
Next i

Application.ScreenUpdating = True

End Sub

Last edited by sym; 01-29-2004 at 08:16 AM.
sym is offline   Reply With Quote
Old 01-29-2004, 08:20 AM   #3
sym
Member (7 bit)
 
Join Date: Nov 2001
Location: Rochester, NY
Posts: 87
Here are the example workbooks
Attached Files
File Type: zip exampleworkbooks.zip (14.4 KB, 40 views)
sym is offline   Reply With Quote
Old 02-10-2004, 11:29 PM   #4
Member (6 bit)
 
Join Date: May 2000
Posts: 49
Thanks very much for your help! This works perfectly and is definately more than I would have expected to receive. Thanks again!
merlin63 is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes 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 On
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 12:46 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2