View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
sebastienm sebastienm is offline
external usenet poster
 
Posts: 694
Default In Excel,VBA. I need help to name a range.

Hi
Say in sheet Sheet1 i have two rows of headers then data starting in A3 (A1
and A2 beeing filled with headers)
The following code creates a workbook-level named range called MyName:

ActiveWorkbook.Names.Add Name:="MyName", RefersTo:= _
"=OFFSET(Sheet1!$A$4,0,0,COUNTA(Sheet1!$A:$A)-2,1)"

-The range starts in sheet Sheet1!A4
- it is offset by 0 (zero) rows, 0 (zero) columns
- and its size is:
- Counta($A:$A)-2 rows = data rows = number of non empty rows in A:A
minus the 2 non-empty header rows.
- and 1 column
(you could change this part to get a wider range, eg:
CountA(Sheet1!$3:$3) )

I hope this helps
Sebastien

"rangerpooch" wrote:

In Excel. Using VBA to write code. I need help to name a range where the
upper left is known and the lower right varies