Macro: Create Named Ranges. Unknown Columns/Rows

Sep 9, 2006

I need to make named ranges from an unknown number of columns(at least 1) each with an unknown number of rows. Each column has the name of the named range as the first row, and then a variable number of rows containing part numbers.

I can do it 1 by 1, but id rather do it in a loop so that blanks dont cause errors. there will be different people using versions of this sheet with different model/part number information What i've tried: Count number of colums with row 1 containing data (11 max, which is more than will ever be used) add into array(I know i dont really need to add into the array, but i might use it later for some other code). The problem i'm having is finding the range of rows that need added to the named dynamic range and adding it.

modelcount = Range("G7") 'G7 (for now) contains =COUNTA(H1,I1,J1,etc)

For i = 1 To modelcount
Redim Preserve Models(0 To i)
Models(i) = Cells(1, i + 7)
Range1 = Cells(2, i + 7).Address(xlA1)
lastRow = Cells(rows.Count, i + 7).End(xlUp).Row
Range2 = Cells(lastRow, i + 7).Address(xlA1)
Reference = Cells(2, i + 7).Address(xlA1)
ThisWorkbook.Names.Add Name:=Models(i), _
RefersTo:="=OFFSET(Reference,0,0,counta(Range1:Range2),1)", Visible:=True
Next i

This gets me the range i need, but doesnt create the named range properly. If i go to insert>names>define, the named ranges are created, but they dont relate to the data in any columns. It shows the variable names rather than the cell range the variable represents.

View 2 Replies


ADVERTISEMENT

Macro To Create Named Ranges Based On A Header Row.

Oct 14, 2009

I need a macro that can set up some named ranges using the text in the header row and the sheet name. The header row will always be in row one, but the number of columns will be dynamic. The amount of rows in the range will need to be dynamic also. To clarify, every used cell stating in row 2 in a column will be the named range with the sheetname+text in row one of the column the actual name.

View 4 Replies View Related

How To Create Macro That Loops All Named Ranges In Worksheet

May 1, 2012

I am trying to creat a macro that loops all the named ranges in a worksheet named "Labels", and copy the data to a new worksheet for each named range it finds in the same workbook and name each worksheet with the named range name.

View 5 Replies View Related

Creating Multiple Named Ranges X Rows High X Columns Wide

Mar 13, 2012

I need to create hundreds of named ranges going down a single sheet.

The name of the first range is in cell a1 and is 13 columns wide and 7 columns high (a1:m7)

The next name is in a8 and the range is a8:m14 and so fourth

If it's easier on a separate sheet I can have a list of names I want in column A and then the cells they refer to in column B.

E.g.

A B

Range1 Sheet1!A1:M7
Range2 Sheet1!A8:M14
Range3 Sheet1!A15:M21

View 2 Replies View Related

VBA Macro To Create Multiple Data Validation Lists From Variables & Named Ranges

Nov 10, 2008

I cant seem to find the correct syntax for creating 14 validation lists using array members as the source of the named ranged. The validation lists are stored on a different worksheet, the Named Ranges are created fine, as are the ranges that are having the validation applied. The Syntax I am having a problem with is

Public Sub assignDVList(WSD As Worksheet, sListName As String)
Dim DVListName As String
DVListName = "DV" & sListName
Application.Goto Reference:=sListName
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=" & DVListName

It is the Formula1:="=" & DVListName that is creating the headache. The sub is called as the array moves through the columns, using the header row as the Name for the Named Range, and the data Validation worksheet uses the same naming except it has DV in front.

View 4 Replies View Related

Create A Set Of Named Ranges

Jul 10, 2009

I'm trying to make my worksheet generate a bunch of named ranges whenever it is activated. However, I'm getting a "Not a valid name" error on the line in red. The value of r is a string, so I really don't see what the issue is. Another time, I got a object defined error, but I think I've declared everyhing too. That line is very similar to the line above, and tends to work once (the first time around the loop). After that, I get the errors I mentioned.

View 4 Replies View Related

Range Of Cells Of Known Columns But Unknown Rows

Mar 19, 2008

I'm working to build a macro to help clean up data I download out of our company's online resources. I know that the data will run from column A to N but the number of items (and thus number of rows)will change. I need to sort all used rows except for the last one (which containes totals and I don't want to include in my sort). So right now I'm just trying to figure out how to select from A3:NX, where x is the row above the last used row.

What I've managed to find so far on the forums is

Offset("$A$3", 0, 0, (Match(9.99999999999999E+307, "N:N", 1) - 1), 14).Select

which I think should find the last row in N to have a number in it, minus 1. However I'm getting a compile error that function or sub are not defined. (seemingly refering to the Match, but I'm not sure).

View 6 Replies View Related

Adding Named Ranges - Use Offset Or Create Using VBA

Jul 31, 2012

I keep losing my named ranges when attempting to reopen a particular file I am working on. I get the "excel found unreadable content....." error message and then when it corrects, the range names are all gone. is it efficient to create the named ranges at open? Otherwise how should it be done so that my workbook will definitely have these names each time its used?

View 3 Replies View Related

Create Named Ranges From Column And Row Headers

May 6, 2013

Is there any way in Excel to create single-cell named ranges from a combination of the labels in the rows and column of a spreadsheet.

Here is an example:

CompanyA
CompanyB
CompanyC
CompanyD

Sales
100
200

[code]....

I would like the first cell (containing the 100) to have a defined name of (something like) "SalesCompanyA", and the second cell to be "SalesCompanyB". And so on - e.g. the cell with 300 in it should be "CostCompanyA".

I can do it manually, but I have a huge spreadsheet & was hoping it could be automated. Just to be clear, it needs to be a single cell range. I know you can create a range from a selection - but this seems to create ranges of the entire row and/or column.

View 6 Replies View Related

Create Dynamic Named Ranges With Code

Oct 13, 2007

I am employing code to label dynamic ranges that takes the form of,

ActiveWorkbook.Names.Add Name:="dms", RefersToR1C1:="=OFFSET(DMS!R10C5,0,0, COUNTA(DMS!C5),COUNTA(DMS!R10))"
'dms_j
ActiveWorkbook.Names.Add Name:="dms_j", RefersToR1C1:="=OFFSET(DMS!R11C10,0,0,MATCH("" * "",DMS!C10,-1),1)"
'dms_p
ActiveWorkbook.Names.Add Name:="dms_p", RefersToR1C1:="=OFFSET(DMS!R11C16,0,0,MATCH("" * "",DMS!C16,-1),1)"
'dms_r
ActiveWorkbook.Names.Add Name:="dms_r", RefersToR1C1:="=OFFSET(DMS!R11C18,0,0,MATCH("" * "",DMS!C18,-1),1)"
'dms_t
ActiveWorkbook.Names.Add Name:="dms_t", RefersToR1C1:="=OFFSET(DMS!R11C20,0,0,MATCH("" * "",DMS!C20,-1),1)"

The dynamic ranges are getting entered but the problem is that the range "dms" overshoots by six cells into blank cells at the bottom of the table, and the rest of the ranges overshoot by ten cells into blank cell area. I have deleted, cleared and destroyed everything around the table and re-sized the active area to no avail.

View 9 Replies View Related

Create Chart Using Dynamic Named Ranges For Series

Jul 27, 2012

I've created my dynamic named ranges using the OFFSET function, ex.

="OFFSET(SAMPLE!$D$4,1,0,COUNTA(SAMPLE!$D:$D)-1,1)"

I'm now trying to get my chart to use that range. I read at [URL] .... that I need to make sure my series reference is a fully qualified reference. So I've entered that series reference using the name of the workbook followed by the range name (=2012-PIRS.xlsx!SAM_CLAR2DEL). I have two copies of my workbook (one as xlsm with VBA project, and one with xlsx without VBA) and I can't get Excel to accept the series value in either workbook.

ERROR MSG:
The formula you typed contains an error. Try one of the following:
- Make sure you've included all parentheses and required arguments.
- To use a function, click Insert Function on the Formulas tab (in the Function Library group).
- If you include a reference to another sheet or workbook, verify that the reference is correct.
- If you are not trying to enter a formula, avoid.........

View 1 Replies View Related

Dynamically Create Named Ranges Based On Cell

Dec 16, 2007

I am looking for a solution to dynamically create named ranges according to the contents of cells in a particular column. The following code works for 1 word names, but in many cases the title cell contains numerous words separated by spaces. Is there a way I can adapt this code so that it will name the ranges with the spaces removed? For example, where cell C2 contains the narrative 'Sales Ledger Control', I would want the range name 'SalesLedgerControl'.

Range("R2:Z2").Name = Range("C2")

The named ranges are referred to in numerous other worksheets, where selecting a particular narrative from a listbox creates a dependant drop-down in the adjacent cell (eg if Sales Ledger Control is selected, the dependant list contains names of customers). FYI, the data validation in the other worksheets ignores the spaces in the range names, ie: =INDIRECT(SUBSTITUTE(G2," ",""))

It would not take me long to name the ranges manually, but a macro is preferable because the narratives in the title cells will often change and the range names will obvioulsy also therefore change.

View 4 Replies View Related

OFFSET-COUNT-MATCH Method To Create Dynamic Named Ranges

Dec 25, 2008

I use the standard OFFSET-COUNT-MATCH method to create dynamic named ranges in my Excel projects. Needless to say, this method won't work on a spreadsheet with formulas extending beyond the current range. The count function counts the cells containing formulas, even though they may contain no data. Does anyone know how to construct a formula that will IGNORE the "formula only" cells??

View 3 Replies View Related

Can Automatically Create Named Ranges Based On Adjacent Cell Values?

Jul 11, 2013

Macro that could look at a row and take the values of two cells, combine them and then create a range name for a third cell in the row.

For example; for row 5420, in column C there is the word Florida, in column D there is the number 6235, and in column F there is a sentence or two. Is there a way to automatically create a named range for the cell of column F that would be named FLORIDA6235? And if so, can the macro do this for every row even if the word and/or the number changes.

I have roughly 28,000 rows and nine columns that I am working with. That's why I was wondering if there was a way to automate this. There are 10 states and I don't know how many different numbers attached to the states, however there are many state and number combinations that repeat, so there would be several rows with Florida in column C, 6235 in column D but a different description in column F.

View 9 Replies View Related

How To Use Named Ranges In VBA Code Using Columns And Variation On Range

Mar 17, 2014

I am trying to clean up my code by using named ranges so that it will still work if/when others add columns or rows to the spreadsheet. These should be pretty easy solutions for most of you but I can't seem to find any answers online.

Here are 2 examples of the code I am trying to update:

I was thinking that replacing "A" with "namedRange" would work but I suppose that's not how the Columns application works. How can I modify the code below to work with a named range instead of the fixed column "A"?

[Code].....

For the following I would have thought that replacing "AU" with "namedRange" would do the trick as that's how things have worked for me in the past using the Range application. Unfortunately I get an error when I make the change.

[Code] .....

View 2 Replies View Related

Delete Rows Without Named Ranges Failing

Apr 3, 2008

I have a dynamic named range in my worksheet:

Range Name = AssignDt
RefersTo: =OFFSET('Raw Data'!$W$2,0,0, COUNTA('Raw Data'!$A:$A)-1,1)

I perform a routine in VBA which deletes unwanted rows of data from my worksheet. The problem occurs if row 2 happens to be one of those rows. It not only deletes Row 2, but it also deletes my Named Range.

View 7 Replies View Related

Change Chart Data Series (rows) Using Named Ranges?

Mar 13, 2013

I have a chart in a workbook that works fine by looking at the following data series:

=Workings!$A$2:$C$35

In the data series above...where the numbers are 2 and 35 I have named ranges "CHART_Start_Row" and "CHART_End_Row" which will change dynamically as appropriate and can replace these static numbers - but how do I incorporate these named ranges into the data series reference?

View 2 Replies View Related

Macro For Two Named Ranges

Feb 24, 2009

Macro for two named ranges. I have this code, which works fine...

View 4 Replies View Related

Macro To Remove Named Ranges With #REF

Nov 29, 2006

VBA code to remove all named ranges in a workbook that contain "#REF" in the reference. I have some legacy workbooks and some have hundreds of invalid named ranges, it's painstakingly slow to delete them manually, a macro to wipe out the ones with #REF in them

ie:

Names in Workbook:
Print_Area

Refers to:
='I:ReportngAlain[buckets.xls]#REF'!$U$774:$AC$811

This one has the #REF in the reference, I'd like ones like this go be wiped out.

View 9 Replies View Related

Define Only 2 Named Ranges From List Of Named Ranges

Apr 28, 2014

I have written this macro to convert into a csv file to run for all defined named ranges in the activesheet. It run jst perfect when I hit SAVE button and it creates that many different CSV files for each named range.

However I am trying to use same macro in the another file and the problem I am facing is there a lot more named ranges and I want to run the macro for only selected NAMED RANGE. In this case 2 Named Range / 24 Named range.

What part of code do I need to change and to what to make it work for just 2 named ranges ?

View 6 Replies View Related

Copy And Paste From Unknown Named Worksheet?

Dec 22, 2011

I have a workbook that contains budgets for as many as 50 divisions. I don't always know what the names of the divisions are going to be. I need a macro that will go through each worksheet and copy aa1:ao200 and paste it to a worksheet named "upload" in the next available row.

Here is something that i found here but i cant make it work.

Sub Macro4()
' Macro4 Macro
For Each ws In ActiveWorkbook.Worksheets
With ws
Range("AA1:AO200").Select
Selection.Copy
If Application.WorksheetFunction.CountA("B:B") = 0 Then

[code]....

View 2 Replies View Related

Macro To Copy Named Ranges In A List To Another Worksheet

Jan 27, 2012

I looking for a macro to look in a list in worksheet "Map_Ref", and take the Range Name of column "A" and copy that range in the corresponding Tab and range as specified in Columns "C" and "D" (i,e. take range name "BB Staff Counts_Tenured" from cell "A2" and copy that range in worksheet "Sheet2" (as specified in cell C2), range "A2" (as specified in cell D2). And so on.

List of worksheet "Map_Ref":

Column AColumn BColumn CColumn DTable/Range Title/Name:
Range in Tab "CMD_1"Copy to Tab:To Range:BB_Staff_Counts_TenuredA126..Q156Sheet2A2Branch_Counts_BBmarketsA35..
C47Sheet2A59Branch_Counts_Chase_SBRM_RegA30..E33

[Code] ........

View 6 Replies View Related

Macro To Print Multiple Named Ranges To Single PDF?

Apr 29, 2013

What I have is a large number of sheets in a workbook (26 to be exact). Each of these sheets has one specific named range. The file itself is quite large so I would like to print these ranges to a single PDF file. I did my best to search for this topic in the forums and while I did find some macros that were close, there was some sort of piece of code missing. Also, will how I list the named ranges determine the order of how they will show up in the PDF File?

View 3 Replies View Related

Macro Quit Working - Dynamic Named Ranges

Jun 1, 2006

I did the huge macro that names a bunch of dynamic ranges, all similar to the following: Range("=OFFSET(BD!$C$32,0,1,1,COUNT(BD!$32:$32))").Name = "ChtBDLabel"

I tested it as I went along, so I know it was working. Then I worked on several other tasks (copying the range to another location on the sheet, making graphs from the ranges). Now when I go back to run this again, I get: Run-time error '1004':
method 'Range' of object '_Global' failed. I went and looked what I thought were my named ranges, and they were wrong (not dynamic, just a cell reference). I deleted them and tried again with same error.

View 3 Replies View Related

Formatting Unknown Ranges Based On Contents Of A Column

May 19, 2009

i can't seem to figure this one out.

I attached a file showing how i am trying to format data (the second tab).

The big issue is the counting to format. (the formatting itself is obviously easy.)

The number of columns is not always standard so i need to count for it.

the number of rows in each "room number" is also not always standard, which means i also need to count for those.

If anyone has had experience trying to do something like this i would appreciate the help.

i know it is possible because i had one that someone had given me years ago, unfortunately i lost it in a hard drive failure...also years ago.

if it isn't obvious what i am trying to do, let me know and i will try to be clearer.

View 9 Replies View Related

Named Ranges On Multiple Sheets With The Same Named Range & I Cant Figure Out How To Do This

Jun 2, 2006

I need to create a named range on multiple sheets with the same named range & i cant figure out how to do this. EG :- I want to create a named range called "_SubUnitRows" on sheet1 starting from "A1:A50" & other named range again called "_SubUnitRows" on Sheet2 starting from "A1:A25" ...

View 2 Replies View Related

Use Macro To Create Dynamic Ranges

Jan 28, 2010

I am looking for a macro that will allow me to create a dynamic range based on the settings I give it. I would like the dynamic range to be called tracking_number and it to have a reference to =Offset(MainReport!$A$2,0,0,COUNTA(MainReport!$A:$A),1)

If this is possible I would really appreciate it. The reason I need this is because I have 2 workbooks. They are the one with the MainReport in it and then the Master workbook. Every day the workbook containing the MainReport is overwritten with more data, so I can not store a dynamic range and reference it each day.

View 9 Replies View Related

Combine Two Named Ranges Into 3rd Named Range

Mar 14, 2013

Merge two columns into one list in excel

I would like to combine List1 and List2 into a 3rd named range called List3. I was wondering if this were possible without using any additional cells/columns (i.e. I don't want to use Column C like in the example shown in the link above).

Here's the formula from the example:

Code:

=IFERROR(INDEX(List1,ROWS(C1:$C$1)),IFERROR(INDEX(List2,ROWS(C1:$C$1)-ROWS(List1)),""))

I've played around with it, but could not come with any that worked.

View 3 Replies View Related

How To Loop Through Dynamic Ranges Using Columns Rather Than Rows

Jun 23, 2014

I have a list of several hundred columns, beginning with column "G:G", with varying numbers of rows of data in column - each row dipicting a monthly data point. I'd like to average the numbers in each column (need to average over the appropraite time-frame) and compare that average with the corresponding average (same time-frame) for benchmark (column"F:F"). The problem is I don't have the same number of data points in each column; some have data points for every month for the past 33 years, and some just a few years; almost all have differing beginning and ending dates as well.

[Code] ....

View 9 Replies View Related

Randomly Select Rows, Columns Or Ranges

Oct 18, 2006

by what means is it possible to unselect randomly selected areas, rows, columns from all sheets?

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved