Populate a range with formulas based on value in a cell

mystiedx

New Member
Joined
Jun 27, 2021
Messages
18
Office Version
  1. 2019
Platform
  1. Windows
Hello to all!

I have 2 sheets, called A and B.

In Sheet B, I have a cell, F2, that contains an IF formula. This formula extracts a value from sheet A.

In sheet B, I also have a range of cells that needs to be populated with formulas based on the resulting value in F2.

I've written the VBA code to auto fill the range with formulas. However, I don't know where to place the code. I've tried to put the code in Worksheet's Change, SelectionChange, Activate methods but nothing works.

Any help will be most welcome.

Thank you.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
please provide minisheet.
this should be resolved with no vba.
I actually found where the problem is. But I'm sending you all the same. I would love to know how to do this without VBA.

mini sheet.xlsm
ABCDEF
2Grade10 Op ASubject:Computer Science
3Roll7
4P1P2Exam Mark
5Serial noName100
61Jim102333
72Jack0
83Jill0
94Joe0
105Anne0
116Sophie0
127Millie0
138 
149 
10 Op A
Cell Formulas
RangeFormula
F2F2=IF(OR($A$91="10",$A$91="11"),INFO!$B$10,IF(OR($A$91="12",$A$91="13"),INFO!$B$11,INFO!$B$9))
B2B2=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)
B3B3=COUNTA(B6:B45)
F6:F14F6=IF(ISBLANK($B6),"",ROUND(C6+D6,0))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C6:E45Cell Value>79.5textNO
C6:E45Cell Valuebetween 34.5 and 40.4textNO
C6:E45Cell Value<34.5textNO
F6:F45Cell Valuebetween 39.5 and 49.4textNO
F6:F45Cell Value<39.5textNO
 
Upvote 0
alright, but why use if?
why dont you use vlookup or hlookup or xlookup to search for values with criteria?

you did not provide the second sheet.
 
Upvote 0
alright, but why use if?
why dont you use vlookup or hlookup or xlookup to search for values with criteria?

you did not provide the second sheet.
mini sheet.xlsm
BCDE
5Computer
INFO


There's a formula missing in the first sheet. It's in cell A91. I've used LEFT function to extract the grade from the value in B2. That's why I have not used Lookup. The value in F2 depends on the value in B2.
 
Upvote 0
mini sheet.xlsm
BCDE
5Computer
INFO


There's a formula missing in the first sheet. It's in cell A91. I've used LEFT function to extract the grade from the value in B2. That's why I have not used Lookup. The value in F2 depends on the value in B2.
mini sheet.xlsm
M
21
INFO
 
Upvote 0
mini sheet.xlsm
M
21
INFO
mini sheet.xlsm
ABCDEFGH
1Fill in following information:
2
3School
4Teacher
5DepartmentComputer
6Year2121-2022
7
8Subject Names
9Grades 7-9ICT
10Grades 10-11Computer Science
11Grades 12-13Computer Science
12
INFO
 
Upvote 0
you can use vlookups with left on the array or lookuped values.

Also,can you prepare those tables as they should be?
I don't see correlation between sheet from post1 and post 7

also describe in details what you want to achieve here from the start, since no1 here exept you is familiar with those files
 
Upvote 0
you can use vlookups with left on the array or lookuped values.

Also,can you prepare those tables as they should be?
I don't see correlation between sheet from post1 and post 7

also describe in details what you want to achieve here from the start, since no1 here exept you is familiar with those files
OK. Let me explain.

This is a model mark book to be used by teachers. On the first sheet (INFO - Sheet A), they will fill in their details.

Then there will be one sheet for each class the teacher works with, ranging from grade 7 to 13 (Sheet B is one example of such a sheet). Not all teachers work with all grades. The workbook will calculate the final mark of students based on the different papers they sat for.

Now, for grade 10 onward, the number of papers differ from subject to subject, and the formula used to calculate the final mark is also different.

What I've done:
In sheet INFO, the teacher will enter the name of the subjects for the different grade levels (7-9, 10-11, 12-13) as they may be different.
On the other sheets, I've used LEFT to extract the grade from the name of the class, then used this in an IF formula to populate the subject field (F2). Note that the subject will be different for each teacher.
I've used VBA to populate the Exam Mark column with the appropriate formula according to the subject in F2. I've kept the formulas relative to make the mark book flexible.

I had posted initially because I had thought my code wasn't working. But then I found my mistake (a stupid one ?).

But then you said the populate formula part could be done without VBA. And I'd like to learn how.
 
Upvote 0
Alright,
There are couple of ways this can be done, but:
Firstly b4 I even start, is this the final layout or can't be changed? (To proper columnar database layout, which is better to work on.)
Book2
ABCDEFGH
1Fill in following information:
2
3School
4Teacher
5DepartmentComputer
6Year2121-2022
7
8Subject Names
9Grades 7-9ICT
10Grades 10-11Computer Science
11Grades 12-13Computer Science
12
Sheet1


Also, grades 7- 9 have an ict subject while I do not see it on the main file from post1.
next thing is u can use indirect to grab values from different sheets or tables (its better to use tables ctrl+t)

and then its easy to find a way to either filter data or use some lookup function with criteria to look for specific value.

Here is an example of using indirect:

Be aware: this was b4 Tables were introduced, but in the same manner we can create Table nomenclature to retrieve values
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,366
Messages
6,124,514
Members
449,168
Latest member
CheerfulWalker

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