+ Reply to Thread
Results 1 to 5 of 5

Automate defining names

  1. #1
    Johnny
    Guest

    Automate defining names

    VBA snippet:

    week = InputBox("Enter the week number", week)
    ActiveWorkbook.Names.Add Name:="Eddie", RefersToR1C1:="='11'!R2C2"

    Two things I need to do:

    1. Substitute week for '11' (having syntax problem).
    2. AND week with Eddie (for example =" "Eddie" & week")


  2. #2
    Nick Hodge
    Guest

    Re: Automate defining names

    Johnny

    try this

    week = InputBox("Enter the week number", week)
    ActiveWorkbook.Names.Add Name:="Eddie_" & week, RefersToR1C1:="=" & week &
    "!R2C2"

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    [email protected]HIS

    "Johnny" <[email protected]> wrote in message
    news:[email protected]...
    > VBA snippet:
    >
    > week = InputBox("Enter the week number", week)
    > ActiveWorkbook.Names.Add Name:="Eddie", RefersToR1C1:="='11'!R2C2"
    >
    > Two things I need to do:
    >
    > 1. Substitute week for '11' (having syntax problem).
    > 2. AND week with Eddie (for example =" "Eddie" & week")
    >




  3. #3
    Johnny
    Guest

    Re: Automate defining names

    Nick,

    Works as requested, thank you. But here's a followup question if you
    don't mind:

    Instead of hard-coding the names (ie. Eddie), what would the syntax
    change be to get the name from the adjacent cell (ex. B2). I've tried
    substituting both B2 and R2C2, and I get a run-time error 1004.

    Thanks again
    John


  4. #4
    Bob Phillips
    Guest

    Re: Automate defining names

    week = InputBox("Enter the week number", week)
    ActiveWorkbook.Names.Add Name:= Range("B2").Value & "_" & week,
    RefersToR1C1:="=" & week & "!R2C2"

    or if it is relative (one column to the right) to the activecell then

    week = InputBox("Enter the week number", week)
    ActiveWorkbook.Names.Add Name:= Activecell.Offset(0,1).Value & "_" & week, _
    RefersToR1C1:="=" & week & "!R2C2"

    --
    HTH

    Bob Phillips

    "Nick Hodge" <[email protected]> wrote in message
    news:[email protected]...
    > Johnny
    >
    > try this
    >
    > week = InputBox("Enter the week number", week)
    > ActiveWorkbook.Names.Add Name:="Eddie_" & week, RefersToR1C1:="=" & week &
    > "!R2C2"
    >
    > --
    > HTH
    > Nick Hodge
    > Microsoft MVP - Excel
    > Southampton, England
    > [email protected]HIS
    >
    > "Johnny" <[email protected]> wrote in message
    > news:[email protected]...
    > > VBA snippet:
    > >
    > > week = InputBox("Enter the week number", week)
    > > ActiveWorkbook.Names.Add Name:="Eddie", RefersToR1C1:="='11'!R2C2"
    > >
    > > Two things I need to do:
    > >
    > > 1. Substitute week for '11' (having syntax problem).
    > > 2. AND week with Eddie (for example =" "Eddie" & week")
    > >

    >
    >




  5. #5
    Johnny
    Guest

    Re: Automate defining names

    Bob, Nick,

    Huge help! Many thanks.

    John


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1