Home » excel » excel – Formulas to populate spreadsheet with data

excel – Formulas to populate spreadsheet with data

Posted by: admin May 14, 2020 Leave a comment

Questions:

I want to populate some cells given certain condition. The thing is, I have no idea how to do this with just formulas (can’t use macros or the sort).

Anyways, here’s my workbook, with its **sheets**:

**Sheet1**
TASK     Week
Test     1
Test2    1
Test3    1
Test4    2
Test5    3
Test6    2
Test7

**Sheet2**
Week
2

TASK
Test4
Test6

What I’ve been trying to do is:

  • Populate Sheet2 tasks based on the week chosen.
  • If I choose week #2 (in Sheet2), it should populate the task list (on the same sheet) with the tasks from Sheet1 that have that week number.

For example, right now it is (hypothetically) already loading tasks with a week == 2.

Any doubt, just let me know! I hope I made my issue clear.

Thank you very much in advance!

How to&Answers:

Okay, I found a better solution. This one requires an extra helper column on Sheet2, but it at least returns a compact list of matches (no weird spacing).

On Sheet2, in the first row of your list of matches (A3 in this example) enter the following:

=IFERROR(INDEX(Sheet1!$A$1:$A$7,B3),"")

In the adjacent cell in the next column (B3 here) enter the following:

=IFERROR(MATCH(2,Sheet1!$B$1:$B$7,0),"")

where 2 is the week # you are matching.

In the next row enter the following formulas (in A4 and B4 respectively):

=IFERROR(INDEX(OFFSET(Sheet1!$A$1:$A$7,SUM(B$3:B3),0),B4),"")

and

=IFERROR(MATCH(2,OFFSET(Sheet1!$B$1:$B$7,SUM(B$3:B3),0),0),"")

You can fill down this row of formulas as far as you like.

Answer:

Here’s the first way to do this I thought of. There are probably better, more elegant solutions, but I thought I’d share.

If you know the total number of tasks in your list on Sheet1, say n, you can do the following:

  1. On Sheet 2 where you want your list of matching tasks, select from A4 (or whatever you want the top of your list to be) down to A(4+n-1). So for your sample data, select A4:A10
  2. Without changing the selection, type the following formula:

    =IF(Sheet1!B2:B8=2,Sheet1!A2:A8,"")

    where 2 is the week # you want to match.

  3. Enter the formula by pressing Ctrl+Shift+Enter.