View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Gord Dibben Gord Dibben is offline
external usenet poster
 
Posts: 22,906
Default Naming a range in a module

Sue

ReqRow = ActiveCell.Row
ReqCol = ActiveCell.Column
ActiveCell.Offset(-1, 0).Range("A1:A2").Select
ActiveWorkbook.Names.Add Name:="ac" & AccCode, RefersToR1C1:= _
"='Work Data'!R" & ReqRow & "C" & ReqCol & ":R" _
& ReqRow - 1 & "C" & ReqCol & ""
ActiveCell.Offset(1, 2).Range("A1").Select

I assume AccCode is a constant or variable from soemwhere.


Gord Dibben MS Excel MVP

On Thu, 10 Jan 2008 01:52:01 -0800, Sue wrote:

I want to select a two cell range and name it using Excel Basic.

The code below does select the two cells with the coordinates of the lower
cell being (ReqRow,ReqCol).

The first two lines of the naming code compile and run but produce nothing
ie no name in list of range names. AccCode is correctly read previously
however. It is a 3 letter string eg veh.

The third line of the naming code will not compile - how do you name a range
rather than a single cell?

Help! There is so much I don't know!

Sue

ReqRow = ActiveCell.Row
ReqCol = ActiveCell.Column
ActiveCell.Offset(-1, 0).Range("A1:A2").Select
ActiveWorkbook.Names.Add Name:="ac" & AccCode, RefersToR1C1:= _
"'Work Data'!R[" & ReqRow & "]C[" & ReqCol & "]:" _
'Comment [" & ReqRow & - 1"]C[" & ReqCol & "]""
ActiveCell.Offset(1, 2).Range("A1").Select