Dynamic Named Range - last x number of items

jbusby825

New Member
Joined
Jan 27, 2016
Messages
25
Office Version
  1. 365
Platform
  1. Windows
I am trying to create a dynamic named range for the last x number of items in my row. I have data in row 9 columns D thru AZ, but I want my named range to be the last 36 columns in that row so i want it to be columns Q thru AZ. Thank you in advance!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
.... for the last x number of items in my row.

Can you please provide more detail? How are you defining the dynamic range? Do you always want the last 36 columns? Or does it depend on the cell contents in the row?

Please also update your Account Details to let us know what version of Excel you're using. With 365, it could be as simple as TAKE(SomeRange,,-36) but I suspect you're using an older version?
 
Upvote 0
Attached is an image of the part of the file I'm currently referencing. as mentioned i'm looking at row 9 for now, but this will eventually carry over into other rows for other named ranges all to be used in charts. my charts will be for 36 month trends so i want to be able to have the dynamic range looking at the last 36 months.
 

Attachments

  • Screen Shot 2024-02-14 at 10.20.53 PM.png
    Screen Shot 2024-02-14 at 10.20.53 PM.png
    36.8 KB · Views: 11
Upvote 0
Perhaps something along these lines?

ABCDEFGHIJKLMNOPQRSTUVWX
1Jan-23Feb-23Mar-23Apr-23May-23Jun-23Jul-23Aug-23Sep-23Oct-23Nov-23Dec-23Jan-24Feb-24Mar-24Apr-24May-24Jun-24Jul-24Aug-24Sep-24Oct-24Nov-24Dec-24
2100.0105.7108.6109.6114.7118.4117.7120.6119.9119.8121.7122.1128.0
3
4EndDateJan-24
5Period (N)6months
6
7ChartDataAug-23Sep-23Oct-23Nov-23Dec-23Jan-24
8120.6119.9119.8121.7122.1128
Sheet1
Cell Formulas
RangeFormula
A1:X1A1=EDATE(DATE(2023,1,1),SEQUENCE(,24,0))
C7:H8C7=CHOOSECOLS(Data,SEQUENCE(N,,MATCH(C4,A1#)-N+1))
Dynamic array formulas.
Named Ranges
NameRefers ToCells
Data=Sheet1!$A$1:$X$2C7
N=Sheet1!$C$5C7

(I haven't applied any checks that your EndDate is not too old/recent)

If you like, you can chart the results without displaying them, by setting :

chart x values: =Sheet1!x
chart y values: =Sheet1!y

where:

x: =CHOOSECOLS(INDEX(Data,1,),SEQUENCE(N,,MATCH($C$4,$A$1#)-N+1))
y: =CHOOSECOLS(INDEX(Data,2,),SEQUENCE(N,,MATCH($C$4,$A$1#)-N+1))
 
Upvote 0
To just create a Named Range.
Code:
Sub One_Possibility()
Dim fc As Long
fc = Cells(9, Columns.Count).End(xlToLeft).Column - 35
ActiveWorkbook.Names.Add Name:=ActiveSheet.Name & "!RowNine", RefersTo:=ActiveSheet.Range(Cells(9, fc), Cells(9, fc + 36))
Sheets("Sheet1").Range("RowNine").Select
End Sub
 
Upvote 0
You can enter this function directly in the Name Manager:


Excel Formula:
=OFFSET(Sheet17!$D$4,0,LOOKUP(2,1/(Sheet17!$D$7:$AAA$7<>""),COLUMN(Sheet17!$D$7:$AAA$7))-35,1,36)

Give it a name you like. This looks for the last used column in row 7, so make sure there's nothing after it.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Dynamic Named Range - last x number of items
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Dynamic Named Range - last x number of items
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
I got called out on the other post. I didn't know that was a thing. I do not do this too often so I apologize. I know for the future though :).
 
Upvote 0

Forum statistics

Threads
1,215,076
Messages
6,122,983
Members
449,092
Latest member
Mr Hughes

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