It's working fine at my end, yet you can change the line from
"RefersToR1C1" to "RefersTo" as below

ActiveWorkbook.Names.Add Name:=sName, RefersTo:= _
        "=OFFSET(" & Sht & "!R2C" & Col & ",0,0,COUNTA(" & Sht & "!C" & Col
& ")-1," & ColCount & ")"


On Fri, May 17, 2013 at 7:50 AM, Cab Boose <swch...@gmail.com> wrote:

> Hi
>
> Have this macro to take the
> See code below.  Comes up with compile error on the last row:
> ActiveWorkbook..........
>
> Is it something to do in not having the sheet name ? If so it would have
> to be taken from the tab. (I now see it is referenced as sht.)
>
> or  Is it something to do with the R1C1 references. I have not used the
> R1C1 reference before, but it appears to be ok.
>
> Any comments? Thanks
> Charlie Harris
> Sub DynamicNames_MultiCol()
>
>   Dim ColCount As Long
>   Dim LabelRow As Long
>   Dim Col As Long
>   Dim sName As String
>   Dim c As Range
>   Dim Sht As String
>
>   'assign row and column parameters
>   '**adjust for the row containing your headings
>   LabelRow = 1
>   ColCount = Selection.Columns.Count
>
>   'grab sheet name
>   Sht = "'" & ActiveSheet.Name & "'"
>
>    Col = ActiveCell.Column
>     sName = ActiveCell.Value
>     If Len(sName) > 1 Then
>       'replace spaces with underscores
>       sName = Replace(sName, " ", "_", 1)
>       'create the name
>       ActiveWorkbook.Names.Add Name:=sName, RefersToR1C1:= _
>         "=OFFSET(" & Sht & "!R2C" & Col & ",0,0,COUNTA(" & Sht & "!C" &
> Col & ")-1," & ColCount & ")"
>     End If
> End Sub
>
>
>
>
>
> --
> Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s
> =TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @
> https://www.facebook.com/discussexcel
>
> FORUM RULES
>
> 1) Use concise, accurate thread titles. Poor thread titles, like Please
> Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice
> will not get quick attention or may not be answered.
> 2) Don't post a question in the thread of another member.
> 3) Don't post questions regarding breaking or bypassing any security
> measure.
> 4) Acknowledge the responses you receive, good or bad.
> 5) Jobs posting is not allowed.
> 6) Sharing copyrighted material and their links is not allowed.
>
> NOTE : Don't ever post confidential data in a workbook. Forum owners and
> members are not responsible for any loss.
> ---
> You received this message because you are subscribed to the Google Groups
> "MS EXCEL AND VBA MACROS" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to excel-macros+unsubscr...@googlegroups.com.
> To post to this group, send email to excel-macros@googlegroups.com.
> Visit this group at http://groups.google.com/group/excel-macros?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Regards,
Anoop
Sr. Developer

-- 
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s 
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @ 
https://www.facebook.com/discussexcel

FORUM RULES

1) Use concise, accurate thread titles. Poor thread titles, like Please Help, 
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get 
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.

NOTE  : Don't ever post confidential data in a workbook. Forum owners and 
members are not responsible for any loss.
--- 
You received this message because you are subscribed to the Google Groups "MS 
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to excel-macros+unsubscr...@googlegroups.com.
To post to this group, send email to excel-macros@googlegroups.com.
Visit this group at http://groups.google.com/group/excel-macros?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to