+ Reply to Thread
Results 1 to 13 of 13

Define Name to current selection

  1. #1
    Registered User
    Join Date
    08-30-2005
    Posts
    67

    Define Name to current selection

    Hi All,

    Can anyone advise on the proper code to define a name to current selection? I've tried Add Name code but it's not working the way I want. It always refers to the same range like for example
    RefersTo:="=sheet1!$a$1:$c$20"

    Thanks.

  2. #2
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hi Eduard,

    try something like this:

    Please Login or Register  to view this content.
    this will refer to the seleccted cells in the worksheet

  3. #3
    Registered User
    Join Date
    08-30-2005
    Posts
    67

    Thanks

    This is it! Thanks a lot, Stuie.
    Last edited by Eduard; 07-25-2008 at 07:12 AM.

  4. #4
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    No problem, glad to help

  5. #5
    Registered User
    Join Date
    08-30-2005
    Posts
    67

    One more ...

    Sorry, Stuie.

    Would you maybe know how do I use the defined names in a formula? Normaly if I define an area as Price and another one as Quantity than I just type in the formul =Price*Quantity. But when I try to do it with a macro it doesn't work.

    This is the code I'm using:

    FormulaR1C1 = "=Price*Quantity"

    Thanks,
    Eduard

  6. #6
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    i usally dont bother with the FormulaR1C1, i have found if you put the forumla un as text that tends to work like:

    Please Login or Register  to view this content.
    and just change the "A1" to the cell you are using

  7. #7
    Registered User
    Join Date
    08-30-2005
    Posts
    67
    This doesn't work either. I figured out that the problem is that the names are defined by absolute addresses, i.e. $A$1:$A$20 and $B$1:$B$20. While in order for the formula to work it should be relative address.

    Any idea how to do that?

    Thanks,
    Eduard

  8. #8
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    so are you defining Price & Quantity as more than one cell?

  9. #9
    Registered User
    Join Date
    08-30-2005
    Posts
    67
    Correct. These are 2 different ranges of cells.

  10. #10
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    okie doke, when you write price*quantity have you got a quick example of how this looks on the spreadsheet as i think it just takes the first cell of each range argument and uses those.

  11. #11
    Registered User
    Join Date
    08-30-2005
    Posts
    67
    Stuie,

    See attached a sample.

    I have a macro code that defines A2:A5 as Price and B2:B5 as Quanity based on the header row. I know it would be easier to enter a formula in C2=A2*B2. But it will not work in case when there are more columns between Price and Quantity.

    So I thought using defined names will be better.

    Thanks,
    Eduard
    Attached Files Attached Files

  12. #12
    Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    if there were for example 3 columns with a price in and 1 column with a qty would you not do =SUM(Price) * Quantity

    or am i looking at this wrong?

  13. #13
    Registered User
    Join Date
    08-30-2005
    Posts
    67
    No. The heading of the 3rd column should actulay read Sum=Price*Column

+ 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