Named ranges and variables
Hi Mats,
The code portion:
' Define the 2 named ranges
With Worksheets("Docs")
.Range("A1:B1").Name = "myRange1"
.Range("A7").Name = "myRange2"
End With
Was only included for demo purposes. In your situation, two ranges would be
set elsewhere.
Simply delete this portion from the demo.
---
Regards,
Norman
"Mats Samson" wrote in message
...
Hi Norman,
no unfortunately not. It won't work with a predefined range as it becomes
static when written in the code. Later, when you've changed position of
the
range then you have to edit the code and change the range. That's why I'm
using named ranges in the code, because you can redefine a named range in
Insert/Name/Define...without changing the code.
My problem is that I want the code to change the named range to the
current
position and different start- and goal- ranges are used depending on
previous
conditions. By branching and narrowing/closing (I don't know the right
expression) the procedures you can shorten and (re)use the code for
different
purposes or conditions.
Thanks anyway!
Mats
"Norman Jones" wrote:
Hi Mats,
Perhaps something like:
Sub Tester02()
Dim CurRange As Range
' Define the 2 named ranges
With Worksheets("Docs")
.Range("A1:B1").Name = "myRange1"
.Range("A7").Name = "myRange2"
End With
If Range("D1") 10 Then '<=== Change condition to suit!
Set CurRange = Range("myrange1")
Else
Set CurRange = Range("myrange2")
End If
Application.Goto CurRange
End Sub
---
Regards,
Norman
|