Using VBA / INDEX / VLOOKUP to return a whole row on a different spreadsheet

thedicewoman

New Member
Joined
Aug 27, 2013
Messages
2
Hello there,

I've trawled the internet and can't seem to get just the right answer for my query: I hope someone here can help.

I have built a report with a front page, a calculations page, a clean data page and an export data page. The Clean Data page picks up what the user exports into the export data page and runs some neat little formulas to remove any erroneous records. It has all of the raw data I need to build the Front Page.

On the Front Page, I'd like to include some tables which will read the Clean Data page and return records (whole rows, around 6 columns) dependant on certain parameters.

So, lets say I want all records (rows) displayed on the Front Page which have 'UK' included in the 'Project Location' column on the Clean Data page. Is there a formula I can use to return:
a) more than one record
b) the entire row of that record?

The aim is for any user to simply enter the Export Data and have a quickly-produced front page report with certain parameneters set to return highlighted records.

Any advice you can give on this would be most appreciated: I am not shy in using VBA for a solution, as long as I can build in a user-friendly 'Generate Report' button. I have 2007.

Many thanks
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi and welcome to the forum,

Here is one possible solution you can try with this example setup:

Excel 2013
ABCD
Project Location:UK
Count:
Column index
Row indexProject LocationProject TypeProject Number
UKA
UKB
UKE

<tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]5[/TD]

[TD="align: center"]6[/TD]
[TD="align: right"]1[/TD]

[TD="align: right"]1[/TD]

[TD="align: center"]7[/TD]
[TD="align: right"]2[/TD]

[TD="align: right"]2[/TD]

[TD="align: center"]8[/TD]
[TD="align: right"]5[/TD]

[TD="align: right"]5[/TD]

</tbody>
Sheet1
Excel 2013
ABC
Project LocationProject TypeProject Number
UKA
UKB
FranceC
GermanyD
UKE

<tbody>
[TD="align: center"]1[/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]1[/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]2[/TD]

[TD="align: center"]4[/TD]

[TD="align: right"]3[/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]4[/TD]

[TD="align: center"]6[/TD]

[TD="align: right"]5[/TD]

</tbody>
Sheet2
The associated formulas for Sheet1 are as follows.

In B2 enter:

=COUNTIF(Sheet2!A$2:A$6, B1)

In A6 (using CTRL-SHIFT-ENTER rather than just ENTER as this is an array formula) and drag down as far as required:

Code:
=IF(
    ROWS(A$5:A5) > B$2,
    "",
    SMALL(
      IF(
        Sheet2!A$2:A$6 = B$1,
        ROW(Sheet2!A$2:A$6) - ROW(Sheet2!A$2) + 1),
      ROWS(A$5:A5)))

In B6 enter and drag across and down as far as required:

=IF($A6 = "", "", INDEX(Sheet2!$A$2:$C$6, $A6, B$4))

Note that an easier approach might just be to use a PivotTable or filters on the original data assuming your users would be comfortable with that.

If you need additional criteria in Sheet1, e.g. like this:

Excel 2013
ABCD
Project Location:UK
Project Type:A
Count:
Column index
Row indexProject LocationProject TypeProject Number
UKA
UKA

<colgroup><col style="width: 25pxpx"><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: right"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]1[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]3[/TD]

[TD="align: center"]6[/TD]

[TD="align: center"]7[/TD]
[TD="align: right"]1[/TD]

[TD="align: right"]1[/TD]

[TD="align: center"]8[/TD]
[TD="align: right"]2[/TD]

[TD="align: right"]2[/TD]

</tbody>
Sheet1

Then you can use the following in B3 and A7 (and down).

In B3 enter:

Code:
=COUNTIFS(
    Sheet2!A$2:A$6, B1,
    Sheet2!B$2:B$6, B2)

In A7 (using CTRL-SHIFT-ENTER rather than just ENTER as this is an array formula) and drag down as far as required:

Code:
=IF(
    ROWS(A$6:A7) > B$3,
    "",
    SMALL(
      IF(Sheet2!A$2:A$6 = B$1,
      IF(Sheet2!B$2:B$6 = B$2,
        ROW(Sheet2!A$2:A$6) - ROW(Sheet2!A$2) + 1)),
      ROWS(A$6:A7)))

If you want further criteria continue the same pattern adding more conditions as required.
 
Last edited:
Upvote 0
HI there,

Thanks very much for your swift reply. I will give this a go: on first glance it seems it will do the trick!

Cheers
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top