Dynamic Range for use in Formula

PhilW_34

Board Regular
Joined
Jan 4, 2007
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hello,

Normally, I would spend more time searching for my solution, but today I'm under a time constraint.

I want to enter this formula in cell C3.

=SUMPRODUCT(($B6:$B2199="Amount")*SUBTOTAL(9,OFFSET(C1,ROW($B6:$B2199)-ROW(C1),)))

However, I need $B6:$B2199 to be a dynamic range. Sometimes it could be B6:B200 or B6:B2300, etc. I want to select B6:Last Row in B.

I have the rest of the code pretty much done. I just can't figure out how to define the range and then put it in my formula. Any help would be greatly appreciated.

Thank you.
Phil
 
Thanks Biff,

I'm just not getting how to apply what you suggested. If I put that formula in C3 just to test it, I get a Value error.

Phil
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I'm stumped. The best I could think of to get rid of the finite property is:

=ADDRESS(MATCH(9.99999999999999E+307,B:B,1), 2)

This would solve for the address of the last cell with a number in column B.

So your formula would become:

=SUMPRODUCT(($B6:ADDRESS(MATCH(9.99999999999999E+307,B:B,1), 2)="Amount")*SUBTOTAL(9,OFFSET(C1,ROW($B6:$B2199)-ROW(C1),)))

But that wouldn't work because the formula would not recognize that as a valid address. If you can find some way to make excel recognize that...
 
Upvote 0
Thanks Biff,

I'm just not getting how to apply what you suggested. If I put that formula in C3 just to test it, I get a Value error.

Phil
You don't put that formula in a cell...

I see you're using Excel 2007...

Let's assume that data is on Sheet1.

  • Goto the Formulas tab>Defined Names>Define Name
  • Name: enter some descriptive name for this range. For this example I'll name it MyRange.
  • Refers to: here's where you enter the formula. =Sheet1!$B$6:INDEX(Sheet1!$B$6:$B$65536,MATCH("zzzzz",Sheet1!$B$6:$B$65536))
  • OK out
Then, your formula becomes:

=SUMPRODUCT((MyRange="Amount")*SUBTOTAL(9,OFFSET(C1,ROW(MyRange)-MIN(ROW(MyRange)),)))
 
Upvote 0
Thanks for the suggestions guys.

I figured out how to do what I wanted to do.

Code:
Range("B6", Selection.End(xlDown)).Select
        Dim wb As Workbook
        Dim ws2 As Worksheet
            Set wb = ActiveWorkbook
            Set ws2 = ActiveSheet
                wb.Names.Add Name:="tRange", _
                RefersTo:=ws2.Range("$B6", Selection.End(xlDown))

    Range("C3").Formula = "=SUMPRODUCT((tRange=""Amount"")*SUBTOTAL(9,OFFSET(C1,ROW(tRange)-ROW(C1),)))"
    Range("C4").Formula = "=SUMPRODUCT((tRange=""Quantity"")*SUBTOTAL(9,OFFSET(C1,ROW(tRange)-ROW(C1),)))"
    
    Dim lcol As Long
    lcol = Cells(5, 1).End(xlToRight).Column
    
    Range("C3:C4").Copy Destination:=Range(Range("D3"), Cells(4, lcol))

I am not a programmer. I know just enough to cause trouble. I found this solution by piecing together other things I found online. There may be a better way, but it is working for me and hopefully it might help someone else.

Phil
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,901
Members
452,948
Latest member
Dupuhini

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