Setting a formula to use a "column" set in a cell

jack109

Board Regular
Joined
May 10, 2020
Messages
63
Office Version
  1. 365
Platform
  1. Windows
Hi

Is there a way to reference a column to be used by using a cell.

For example if G is in B2, then G used in the formula

eg. =SUM(G2:G12)

If B2's value was P then the formula would change to =SUM(P2:P12)

I've tried searching online but I'm finding it hard to word it without providing the above example

Cheers
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Build the string for your range reference ("B2:B12") like this:
Excel Formula:
B2 & "2:" & B2 & "12"

Then, you can wrap that in an INDIRECT function to tell Excel it is meant to be a range and not a string, and SUM it, i.e.
Excel Formula:
=SUM(INDIRECT(B2 & "2:" & B2 & "12"))
 
Upvote 0
Solution
Hello,
You can use INDIRECT
Excel Formula:
=SUM(INDIRECT(B2 & "2:" & B2 & "12"))
 
Upvote 0
Brilliant, is there a way that you can also set the rows to use , so if B3 was 7 and B4 was 15 it would tell excel using my above example that the range to use would be G7:G15
 
Upvote 0
Yes, follow the exact same process as I explained above. Sew together range references and hard-coded values.
Start of building a formula to build the range. Once that looks right (i.e. your formula returns "G7:G15"), wrap it in the INDEX formula and SUM it.

Give it a try - it will help you learn it, and post back with your attempt if you run into any issue.
 
Upvote 0
Excellent, finally managed it - didn't realise it was that "simple". Thanks for the advice built it as a string first and when that looked right put into the formula and it worked

Excel Formula:
=SUM(INDIRECT(B2&B3&":"&B2&B4))
 
Upvote 0
Excellent, finally managed it - didn't realise it was that "simple". Thanks for the advice built it as a string first and when that looked right put into the formula and it worked

Excel Formula:
=SUM(INDIRECT(B2&B3&":"&B2&B4))
Excellent!

Now that you understand how it works, you will be able to set up more in the future!
 
Upvote 0
Would it be the same sort of method if I just want to set a column in a formula that uses a single cell and not a range, so that B2 would just change the "G"

Excel Formula:
=IF($G10+$T$3=100,"YES","NO"

I am trying myself but wondering if I am on the right track
 
Upvote 0
Anytime you try to build a range dynamically, the formula will return a string value.
So Excel will NOT recognize your built formula as a range, until you wrap it in an INDIRECT function.
That is true regardless of whether your range is one cell, or a range of cells.
 
Last edited:
Upvote 0
Start of building a formula to build the range. Once that looks right (i.e. your formula returns "G7:G15"), wrap it in the INDEX formula and SUM it.

INDEX or INDIRECT? as you mentioned INDEX here but the formula you give was INDIRECT.


Anyway I can get it working in one formula using a "helper" cell say to speak

ALERTS.xlsm
ABCDEFGHIJKLMNO
1
2COLD
3
4
5
6100D6noyes
Sheet5
Cell Formulas
RangeFormula
M6M6=INDIRECT("B2")&ROW()
N6N6=IF((INDIRECT("B2")&ROW())=100,"yes","no")
O6O6=IF(INDIRECT(M6)=100,"yes","no")
 
Upvote 0

Forum statistics

Threads
1,226,467
Messages
6,191,198
Members
453,646
Latest member
SteenP

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