views:

38

answers:

2

Problem: I have data that looks like this and I want to compare the rows to the column values. so is(Table1.t1 = Table2.t1)? kind of thing.

Table 1
A B
x t1
x t2
x t3
x t4

Table 2

A B  C  D  E
x t1 t2 t3 t4

Can I do this in Excel with functions or VBA

+1  A: 

If I'm understanding your question, there are a few ideas that might lead you in the right direction:

  • If you just want to "flip" the data in one of the two tables so you can compare the tables directly, just do a Copy, Paste Special, and check the "Transpose" button. If you want to do this with VBA, just record it as a macro and see what it records.
  • If you want to use VBA, I think that using Cells(row#,col#) instead of Range() is the key.

So lets assume your two tables are in B10:B20 (vertical) and C2:L2 (horizontal). The loop to compare them might look something like:

Sub CompareFlippedTables
    Dim i as integer
    For i = 1 to 10
        If Cells(i + 10,2).Value = Cells(2, i + 3).Value Then
           'Do something useful'
        End If
    Next i
End Sub
BradC
Yes you understand my question perfectly Brad and in fact you answered it correctly for the most part but I was not clear as for the end result. So ultimately, I wan to do a vlookup where I have one column t1 t2 t3 t4 and another column with the same data (in theory) but from a different source. By comparing the 2 columns I can then confirm the data from 2 different sources is the same. Transpose does not give me 1 column for all rows, rather 1 column for each row. I would like 1 column for all rows so i can compare them to the other column of data. Thanks!
Ehsan
A: 

If in A1:B8, you have

x   t1
x   t2
x   t3
x   t4
y   u1
y   u2
y   u3
y   u4

and in A11:E12, you have

x   t1  t2  t3  t4
y   u1  u2  u3  u4

then put this formula in C1 and fill down

=B1=OFFSET(INDEX($A$11:$A$12,MATCH(A1,$A$11:$A$12,FALSE),1),0,COUNTIF($A$1:A1,A1),1,1)

It will return TRUE if the data matches, and FALSE if it doesn't.

Dick Kusleika
Thank you Dick.
Ehsan