View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Create named range for each column not working?

This works for me


Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
cntCol = ws.UsedRange.Columns.Count
cntRow = ws.UsedRange.Rows.Count

' Set name for each column range
cntRng = 1
For i = 1 To cntCol
strRng = i
strAddr = "=" & ws.Name & "!C" & strRng
strRng = "col" & strRng
wb.Names.Add _
Name:=strRng, _
RefersToR1C1:=strAddr
Next i


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Ed" wrote in message
...
I'm attempting to loop through all the columns in the UsedRange and create

a
named range for each one. It loops, and all strings are correct - I just
don't have any ranges when it's finished! What have I done wrong?

Ed

Set wb = ActiveWorkbook
Set ws = wb.ActiveSheet
cntCol = ws.UsedRange.Columns.Count
cntRow = ws.UsedRange.Rows.Count

' Set name for each column range
cntRng = 1
For i = 1 To cntCol
strRng = i
strAddr = ws.Name & "!C" & strRng
strRng = "col" & strRng
wb.Names.Add _
Name:=strRng, _
RefersToR1C1:=strAddr
Next i