michaelsmith559
Well-known Member
- Joined
- Oct 6, 2013
- Messages
- 881
- Office Version
- 2013
- 2007
Here is the current macro:
Here is sheet 1:
Here is sheet 1 after I run macro:
I am trying to replace this formula:
Offset($A$2,0,0,Match(1E+306,$A:$A),1)
with something like this:
OFFSET(myRange.Offset(1,0).Address,0,0,MATCH(1E+306,myRange.Column:myRange.Column),1)
Code:
Sub Insert_Dynamic_Range()
Dim myText As String, myRange As Range, lastRow As Long
myText = Application.InputBox("Enter a Name for Range", Type:=2)
Set myRange = Application.InputBox("Select Where To Put Name", Type:=8)
myRange = myText
With ActiveSheet
lastRow = Cells(Rows.Count, myRange.Column).End(xlUp).Row
ActiveSheet.Names.Add Name:=myText, _
RefersTo:="OFFSET(myRange.Offset(1,0).Address,0,0,MATCH(1E+306,myRange.Column:myRange.Column),1)"
End With
End Sub
Here is sheet 1:
Excel 2012 | ||||
---|---|---|---|---|
A | B | |||
1 | ||||
2 | 5 | |||
3 | 6 | |||
4 | 7 | |||
5 | 3 | |||
6 | 2 | |||
7 | 1 | |||
8 | 8 | |||
9 | 9 | |||
Sheet1 |
Here is sheet 1 after I run macro:
Excel 2012 | ||||
---|---|---|---|---|
A | B | |||
1 | Prices | #VALUE! | ||
2 | 5 | |||
3 | 6 | |||
4 | 7 | |||
5 | 3 | |||
6 | 2 | |||
7 | 1 | |||
8 | 8 | |||
9 | 9 | |||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
B1 | =SUM(Prices) |
Named Ranges | ||
---|---|---|
Name | Refers To | Cells |
Sheet1!Prices | ="OFFSET(myRange.Offset(1,0).Address,0,0,MATCH(1E+306,myRange.Column:myRange.Column),1)" |
I am trying to replace this formula:
Offset($A$2,0,0,Match(1E+306,$A:$A),1)
with something like this:
OFFSET(myRange.Offset(1,0).Address,0,0,MATCH(1E+306,myRange.Column:myRange.Column),1)