+ Reply to Thread
Results 1 to 4 of 4

Choosing a specific Workbook and worksheet from cell values

Hybrid View

  1. #1
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Choosing a specific Workbook and worksheet from cell values

    With the workbook name in B1 and worksheet name in B2 of active sheet. (I will have a second workbook and sheet in B3 and B4). I want to be able to choose those other workbooks so I can manipulate them. The workbooks will be open so don't need to worry about path.

    Why doesn't this code work
    Sub test()
    Dim Wkbk1 As Workbook
    Dim WkSh1 As Sheets
    Set Wkbk1 = Workbooks(ActiveSheet.Range("B1").Value)
    Set WkSh1 = Sheets(ActiveSheet.Range("B2").Value)
    MsgBox (Wkbk1.WkSh1.Range("A1").Value)
    
    End Sub
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Choosing a specific Workbook and worksheet from cell values

    May be
    Sub Test()
        Dim Wkbk1 As Workbook
        Dim WkSh1 As Worksheet
    
        Set Wkbk1 = Workbooks(ActiveSheet.Range("B1").Value)
        Set WkSh1 = Wkbk1.Worksheets(ActiveSheet.Range("B2").Value)
    
        MsgBox (WkSh1.Range("A1").Value)
    End Sub
    In the declare of WkSh1, you would declare as Worksheet not as collections
    And for assigning the worksheet, you would refer to the workbook
    Hope this helps you
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Choosing a specific Workbook and worksheet from cell values

    Ahhhh, thanks. that works perfectly.

  4. #4
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Choosing a specific Workbook and worksheet from cell values

    You're welcome. Glad I can offer some help
    Thanks for the feedback and for the rep points

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 8
    Last Post: 10-27-2014, 11:27 PM
  2. Replies: 1
    Last Post: 04-26-2013, 04:54 PM
  3. Replies: 0
    Last Post: 10-02-2012, 02:01 AM
  4. Choosing workbook for vlookup based on cell value
    By anandvh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-14-2012, 01:33 PM
  5. Manually choosing which worksheet in a workbook to link to
    By titantough in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-17-2011, 02:59 AM
  6. Replies: 0
    Last Post: 07-27-2006, 05:56 AM
  7. Choosing different cell values by user clicking a button
    By alymcmorland in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-04-2005, 11:41 AM

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