![]() |
#1
|
|||
|
|||
![]()
In my workbook, I have many rows in different sheets. In the first cell of each row(column A), there is a name (header) and in the other cells there are some numbers relating to first row (for example, A1 is inflation and A2:A10 are .01,.02 …which are inflation amount of different years). For making my formula more readable, I want to use dynamic relative named ranges. For automating this process, I have written following macro. There are 2 problem with this macro:
1.VBA consider parameters of my macro as text not value (for example, VBA considers cellAddress02 as “cellAddress02” not $A$1 which is what I expect) 2.For making my named ranges relative rather than absolute, I need a VBA function to give a cell address which doesn't have $ signs before the letter (for example, I want A$1 not $A$1) Can anyone help me on these problems? Sub Macro3() 'Dim rng As Range Dim n As Integer Dim myrow As Integer Dim cell As Range Dim cell02 As Range Dim cellAddress As String Dim cellAddress02 As String myname = ActiveCell.Value myrow = ActiveCell.Row Set cell = ActiveCell cellAddress = cell.Parent.Name & "!" & cell.address(External:=False) Set cell02 = Range("A1") cellAddress02 = cell02.Parent.Name & "!" & cell02.address(External:=False) ActiveWorkbook.Names.Add Name:=ActiveCell.Value, RefersToR1C1:= _ "=INDEX(cellAddress02:cellAddress,myrow)" End Sub |
Tags |
address, macro, relative named ranges |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Use of named ranges based on cell content | Intruder | Excel | 12 | 02-25-2019 09:42 AM |
![]() |
SavGDK | Excel | 5 | 05-01-2017 09:41 AM |
How to use named ranges in excel vba? | bosve73 | Excel Programming | 4 | 01-25-2012 09:26 AM |
Dynamic Named Ranges using text | hannu | Excel | 0 | 06-22-2010 04:42 PM |
Can't import home adresses in outlook 2010 from excel named ranges | eekie | Outlook | 0 | 05-14-2010 02:04 PM |