Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Named Ranges and Named Ranges scope. Referencing a named range

  1. #11
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    _.........................

    From Rem 4 in the second demo code, ( Sub FoxyMultiCellNamedRanges() ) we begin to incorporate named ranges into the to bring in the data from the two data files into the main file……


    Rem 4 using named ranges for data in data ranges from data workbooks

    We will create/Add 4 named ranges in total, one for each data range in the two data workbooks, and a name referring to the ranges in the main file where we want to bring in those values

    To help emphasise that named ranges are actually objects which can be “in” any workbook or workbook worksheet, and which can then be referenced from other workbooks in order to get information about to which range they refer, we will introduce another workbook, “StoredNamedRangeNameObjects.xls”. This file will only contain Name objects. We will use this to store the 4 required Named range Name objects. This is quite a crazy idea.
    ( I can’t imagine why anyone would want to do this. I just thought, well, someone ought to do it , :-) …..Or maybe a security possibility?? – Without the file and the named range object’s information, it could be difficult to use other files requiring this information …..Or if you use worksheets scope, then in the worked example you could devote a worksheet for different data ranges – This would have the named range object or objects , and possibly other information about that data in the spreadsheet. The only thing missing would be the data itself, which might want to be kept elsewhere for, for example, security reasons.. )
    Here is the File, “StoredNamedRangeNameObjects.xls” https://app.box.com/s/0dhyk41yumx857539wu0hji5fsekeg2w

    Code sections '4b) and '4c) use the worksheet with Name “DataFileNameObjects” for the name objects referring to the two data workbooks ( "Data1.xls" and "Data2.xlsx" ) data ranges.
    Code Section '4d) uses worksheet “MainFileNameObjects” for the name objects referring to the two Main workbook ( "MasterFile.xlsm" ) data ranges.

    Rem 5 Using the Added data named ranges to bring in data from the data files into the main workbook.
    The basic code line for the Import, as described in the last post are adapted to use the Added data named ranges in this sort of way:

    Range(“=’C:\MyFolder\[MasturFile.xlsm]Tabelle1'B6:C7”).FormulaArray = “='C:\MyFolder\[Data2.xlsx]Tabelle1'!B6:C7”
    becomes:
    Range(“=’C:\MyFolder\[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta1Import”).FormulaArr ay = “='C:\MyFolder\[StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta1Data”

    Range(“=’C:\MyFolder\[MasturFile.xlsm]Tabelle1'NmsObjDta2Import”).FormulaArray = “='C:\MyFolder\[Data2.xlsx]Tabelle1'!B11:C12”
    becomes
    Range(“=’C:\MyFolder\[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta2Import”).FormulaArr ay = “='C:\MyFolder\[ StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta2Data”

    As we are using a different workbook, ( “StoredNamedRangeNameObjects.xls “ ) for the names , both sides of the code lines must have the complete path reference.
    ( As the workbook “StoredNamedRangeNameObjects.xls” is open at the time of using those formulas, we could use
    Range("='[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta1Import").FormulaArr ay = "='[StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta1Data"
    and
    Range(“=’C:\MyFolder\[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta2Import”).FormulaArr ay = “='C:\MyFolder\[ StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta2Data”
    )

    _._____

    At the end of the second code we have the final range info in the main workbook:

    _____ Workbook: MasturFile.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    B
    C
    4
    Nutrition Energy
    5
    Food
    6
    Orange
    50
    7
    Apfel
    60
    8
    9
    10
    Suppliment
    11
    BCAA
    398
    12
    EAA
    400
    Worksheet: Tabelle1

    The current information in the immediate Window ( that produced by code line 1080 ) will be something like this:

    Code:
    '_= ========
    You have 1 named range Name objects in workbook MasturFile.xlsm
    1  Name object Name is  "MainFoodheader" (the same as you gave)
    It has workbook scope and
    it refers to range  "=Tabelle1!$B$5"
    and if in a spreadsheet formula you only want to use
    "MainFoodheader"
    with no preceding info 
    about where that named range is,
    then you must be in any spreadsheet in workbook  "MasturFile.xlsm"
    If you want to be sure to access this named range from anywhere,
    you should use   "='G:\Excel0202015Jan2016\ExcelFox\Blogs\MasturFile.xlsm'!MainFoodheader"
    or alternatively use a similar string like this with any of the worksheets in it:
    "='G:\Excel0202015Jan2016\ExcelFox\Blogs\[MasturFile.xlsm]Tabelle1'!MainFoodheader"
    
    
    
    '_= ========
    You have 1 named range Name objects in workbook Data1.xls
    1  Name object Name is  "Dta1Foodheader" (the same as you gave)
    It has workbook scope and
    it refers to range  "=Tabelle1!$B$5"
    and if in a spreadsheet formula you only want to use
    "Dta1Foodheader"
    with no preceding info 
    about where that named range is,
    then you must be in any spreadsheet in workbook  "Data1.xls"
    If you want to be sure to access this named range from anywhere,
    you should use   "='G:\Excel0202015Jan2016\ExcelFox\Blogs\Data1.xls'!Dta1Foodheader"
    or alternatively use a similar string like this with any of the worksheets in it:
    "='G:\Excel0202015Jan2016\ExcelFox\Blogs\[Data1.xls]Tabelle1'!Dta1Foodheader"
    
    
    
    '_= ========
    You have no named range Name objects in workbook Data2.xlsx
    
    
    '_= ========
    You have 4 named range Name objects in workbook StoredNamedRangeNameObjects.xls
    1  Name object Name is  "DataFileNameObjects!NmsObjDta1Data"
    (you gave "NmsObjDta1Data")
    It has worksheet scope and
    it refers to range  "=[Data1.xls]Tabelle1!$B$6:$C$7"
    and if in a spreadsheet formula you only want to use
    "NmsObjDta1Data"  without any preceding info about
    where that named range is,
    then you must  be in spreadsheet with tab name  "DataFileNameObjects"
    If you want to be sure to access this named range from anywhere,
    you should use   "='G:\Excel0202015Jan2016\ExcelFox\Blogs\[StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta1Data"
    Note: The refered to range is in worksheet  "Tabelle1"
    Note also: The refered to range is in File  "Data1.xls"
    
    
    2  Name object Name is  "MainFileNameObjects!NmsObjDta1Import"
    (you gave "NmsObjDta1Import")
    It has worksheet scope and
    it refers to range  "=[MasturFile.xlsm]Tabelle1!$B$6:$C$7"
    and if in a spreadsheet formula you only want to use
    "NmsObjDta1Import"  without any preceding info about
    where that named range is,
    then you must  be in spreadsheet with tab name  "MainFileNameObjects"
    If you want to be sure to access this named range from anywhere,
    you should use   "='G:\Excel0202015Jan2016\ExcelFox\Blogs\[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta1Import"
    Note: The refered to range is in worksheet  "Tabelle1"
    Note also: The refered to range is in File  "MasturFile.xlsm"
    
    
    3  Name object Name is  "DataFileNameObjects!NmsObjDta2Data"
    (you gave "NmsObjDta2Data")
    It has worksheet scope and
    it refers to range  "=[Data2.xlsx]Tabelle1!$B$11:$C$12"
    and if in a spreadsheet formula you only want to use
    "NmsObjDta2Data"  without any preceding info about
    where that named range is,
    then you must  be in spreadsheet with tab name  "DataFileNameObjects"
    If you want to be sure to access this named range from anywhere,
    you should use   "='G:\Excel0202015Jan2016\ExcelFox\Blogs\[StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta2Data"
    Note: The refered to range is in worksheet  "Tabelle1"
    Note also: The refered to range is in File  "Data2.xlsx"
    
    
    4  Name object Name is  "MainFileNameObjects!NmsObjDta2Import"
    (you gave "NmsObjDta2Import")
    It has worksheet scope and
    it refers to range  "=[MasturFile.xlsm]Tabelle1!$B$11:$C$12"
    and if in a spreadsheet formula you only want to use
    "NmsObjDta2Import"  without any preceding info about
    where that named range is,
    then you must  be in spreadsheet with tab name  "MainFileNameObjects"
    If you want to be sure to access this named range from anywhere,
    you should use   "='G:\Excel0202015Jan2016\ExcelFox\Blogs\[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta2Import"
    Note: The refered to range is in worksheet  "Tabelle1"
    Note also: The refered to range is in File  "MasturFile.xlsm"
    Last edited by DocAElstein; 11-18-2018 at 11:53 PM.

  2. #12
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://eileenslounge.com/viewtopic.php?p=316441#p316441
    https://eileenslounge.com/viewtopic.php?p=324736#p324736
    https://eileenslounge.com/viewtopic.php?p=324990#p324990
    https://eileenslounge.com/viewtopic.php?f=27&t=41937&p=325485#p325485
    https://eileenslounge.com/viewtopic.php?p=325609#p325609
    https://eileenslounge.com/viewtopic.php?p=325610#p325610
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGADdPM65i9PG
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGADdPQHFk_zm
    http://www.eileenslounge.com/viewtopic.php?p=324457#p324457
    http://www.eileenslounge.com/viewtopic.php?p=324064#p324064
    http://www.eileenslounge.com/viewtopic.php?p=323960#p323960
    https://www.youtube.com/watch?v=7VwD9KuyMk4&lc=UgyZCnNfnZRfgwzDlQF4AaABAg
    https://www.youtube.com/watch?v=7VwD9KuyMk4&lc=UgyZCnNfnZRfgwzDlQF4AaABAg. ADd4m2zp_xDADd6Nnotj1C
    s://www.youtube.com/watch?v=7VwD9KuyMk4&lc=UgySdtXqcaA27wQLd1t4AaABAg
    http://www.eileenslounge.com/viewtopic.php?p=323959#p323959
    http://www.eileenslounge.com/viewtopic.php?f=30&t=41784
    http://www.eileenslounge.com/viewtopic.php?p=323966#p323966
    http://www.eileenslounge.com/viewtopic.php?p=323959#p323959
    http://www.eileenslounge.com/viewtopic.php?p=323960#p323960
    http://www.eileenslounge.com/viewtopic.php?p=323894#p323894
    http://www.eileenslounge.com/viewtopic.php?p=323843#p323843
    https://www.youtube.com/watch?v=fEHKPhJxgBA&lc=Ugxx8_MjhC9FDaQgcHN4AaABAg
    https://www.youtube.com/watch?v=jpjYm4UvyWk&lc=Ugx_Qd4rfAN_ZYcJbo94AaABAg. ACGbG9c76OWACGbjKa7H8k
    https://www.youtube.com/watch?v=jpjYm4UvyWk&lc=Ugx_Qd4rfAN_ZYcJbo94AaABAg
    https://www.youtube.com/watch?v=GyPHaydeng0&lc=UgzE4a4f_e_y9Rk5OR94AaABAg
    https://www.youtube.com/watch?v=I5FkNG94BcQ&lc=UgxXnkEHqulXSR5tXwh4AaABAg
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGABa6BSa173Z
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGABa6-64Xpgl
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGABa5ms39yjd
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGABa5ZXJwRCM
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGABa4Pr15NUt
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGABa4I83JelY
    https://www.youtube.com/watch?v=3t8Mk4URi6g&lc=UgzoakhRXOsCaoRm_Nd4AaABAg. 8xzeMdC8IOGADdMo2n-hyF
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 03-25-2025 at 03:44 PM.

Similar Threads

  1. populate control from named range stored in addin
    By MrBlackd in forum Excel Help
    Replies: 8
    Last Post: 05-11-2016, 04:46 PM
  2. Replies: 15
    Last Post: 01-07-2014, 12:42 AM
  3. Automatically Create Multiple Dynamic Named Ranges Using VBA
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 0
    Last Post: 04-24-2013, 03:49 PM
  4. Add Named Ranges To Multiple Workbooks Using VBA
    By Stalker in forum Excel Help
    Replies: 5
    Last Post: 04-23-2013, 12:20 PM
  5. Detect Duplicates In Named Ranges With Cross Check
    By Yegarboy in forum Excel Help
    Replies: 3
    Last Post: 10-09-2012, 11:02 AM

Posting Permissions

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