help comparing query

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Help with a comparing query

Help with a comparing query

resolvedResolved · Medium Priority · Version 2003

Adam has attended:
Excel VBA Intro Intermediate course
Excel VBA Advanced course

Help with a comparing query

Hi,

I am trying to write code that will compare some downloaded data against a "master" list. Where there is a new line, an input box would appear to add the data to the master list.

The main columns I have are:

Sedol, stock name (long), stock name (short).

I am trying to use Sedol as the column to compare.

What kind of functions should I be using?

Thanks

RE: Help with a comparing query

Hi Adam

Thanks for your question


Can you clarify my understanding

You are downloading data and you wish to compare the values contained in a column called Seedol, with a similar column in the master list. If you find rows in the downloaded data that have values not contained in the master list, then you wish to add that data to the master list.

Is this correct?

Thanks

Stephen

RE: Help with a comparing query

Hi Stephen thanks for your response. Yes that is correct. The requirement I have is that the downloaded list is compared to the "master" list and any new additions to the downloaded list bring up an input box that populates the master list.

Many thanks

Adam.

RE: Help with a comparing query

Hi Adam

Thanks for the clarification

I have written some code that does what you need

It simply goes through the downloaded data line by line and for each line goes through the master list line by line and checks to see if there is a match. If it gets through the whokle list without finding a match it writes the data to the next blank line in the master list

In enclose the code below, and have attached a workbook as an example

Sub ListChecker()

Dim i As Integer
Dim j As Integer
Dim blnItemFound As Boolean
Dim k As Integer

For i = 2 To Range("H1").CurrentRegion.Rows.Count

blnItemFound = False

For j = 1 To Range("A1").CurrentRegion.Rows.Count

If Range("H2").Cells(i, 1) = Range("A1").Cells(j, 1) Then
blnItemFound = True
Exit For
End If

Next j

If blnItemFound = False Then

k = Range("A1").CurrentRegion.Rows.Count + 1

Range("A1").Cells(k, 1) = Range("h2").Cells(i, 1)
Range("A1").Cells(k, 2) = Range("h2").Cells(i, 2)
Range("A1").Cells(k, 3) = Range("h2").Cells(i, 3)

End If

Next i

End Sub


Regards

Stephen

Attached files...

Seedol.xls

Thu 5 Nov 2009: Automatically marked as resolved.

 

Training courses

 

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Adding up rows or columns without seeing formulas

Highlight a column or row and click the Autosum button. This gives you your answer without showing the formula.

View all Excel hints and tips


Server loaded in 0.09 secs.