+ Reply to Thread
Results 1 to 7 of 7

VBA case lookup name range on different sheet

  1. #1
    Registered User
    Join Date
    08-12-2018
    Location
    UK
    MS-Off Ver
    2016
    Posts
    17

    VBA case lookup name range on different sheet

    I am trying to do a dropdown combo box with the first combo box named "shift" and the second "Name" .

    If "shift" = Green for "name" to look on a sheet called Shift_names at a named range called "green" and list in in the drop down

    I currenlty have the code below where am i going wrong I have all my other code for the userform working and adding to a data collection sheet as entries are added.

    Thanks
    Attached Images Attached Images

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: VBA case lookup name range on different sheet

    You never described your problem. What do you expect to happen, and what is happening instead?

    Just looking at your code I suspect there is an issue in the range names. Omit the "Shift_Names!" part and just use the range names.

    An image is almost never helpful. It would have been easier to copy your code and paste it in CODE tags, rather than taking a screenshot then attaching that. It would have been even better to attach your file so I could test my solution before I gave it to you.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    08-12-2018
    Location
    UK
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA case lookup name range on different sheet

    Ive attached the book.

    On the homepage when clicking 'enter standard work result' when filling in the data it currently saves it to a sheet called Data which is all working well. The only bit I cannot do is on the dropdown combo boxes if shift = (colour) it looks for the name range on sheet 'shift_names' and looks for that name range and put it in the drop ddown combo box called names on the userform

    I'm pretty new to using any type opf coding and completed the rest following youtube tutorials.

    Thanks
    Attached Files Attached Files

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: VBA case lookup name range on different sheet

    I was baffled because the code you showed in your first post does not appear in this file. So I started from scratch. I have written code that does what I think you want.

    First, never name anything "Name". That is because Name is a built-in attribute for many things in the VBA object model. When you refer to Me.Name, you are referring to the name of the userform, not the combobox. I have changed your combobox name to ShiftName. If you don't like that you can change it to anything you want.

    Second, I have initialized your Shift combobox index to -1 so it is blank when first displayed. You want to force your user to make a selection, rather than mistakenly allowing them to select Green by doing nothing, which was displayed when the form came up. The only time you want a combobox to show a default value is when it is a true default, that is, you are OK if the user doesn't change it.

    Also, here is a tip from a user interface design standpoint. Selecting the Name combobox doesn't make sense until you have first selected a value from the Shift combobox. So to enforce that order I have added code that disables Name until Shift has a selection.

    Last, I strongly recommend to everyone that they declare variables. Doing so prevents a lot of bugs and runtime errors.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    08-12-2018
    Location
    UK
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA case lookup name range on different sheet

    Quote Originally Posted by 6StringJazzer View Post
    I was baffled because the code you showed in your first post does not appear in this file. So I started from scratch. I have written code that does what I think you want.

    First, never name anything "Name". That is because Name is a built-in attribute for many things in the VBA object model. When you refer to Me.Name, you are referring to the name of the userform, not the combobox. I have changed your combobox name to ShiftName. If you don't like that you can change it to anything you want.

    Second, I have initialized your Shift combobox index to -1 so it is blank when first displayed. You want to force your user to make a selection, rather than mistakenly allowing them to select Green by doing nothing, which was displayed when the form came up. The only time you want a combobox to show a default value is when it is a true default, that is, you are OK if the user doesn't change it.

    Also, here is a tip from a user interface design standpoint. Selecting the Name combobox doesn't make sense until you have first selected a value from the Shift combobox. So to enforce that order I have added code that disables Name until Shift has a selection.

    Last, I strongly recommend to everyone that they declare variables. Doing so prevents a lot of bugs and runtime errors.
    Great stuff, Thank you for doing this. People on here are so helpful, you have made my day.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: VBA case lookup name range on different sheet

    Glad to help, and thanks for the rep!

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

  7. #7
    Registered User
    Join Date
    08-12-2018
    Location
    UK
    MS-Off Ver
    2016
    Posts
    17

    Re: VBA case lookup name range on different sheet

    Can you help one more time.

    when it saves the date it inserts in the data sheet as text so when I try and do a pivot chart with a timeline slicer it says no dates available. I have changed the date cell format to date and it still wont work

    edit

    ive solved it. thanks again
    Attached Files Attached Files
    Last edited by bazfalty; 08-27-2018 at 02:08 PM.

+ 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. [SOLVED] Lookup on different sheet, check range for value
    By x65140 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-18-2015, 03:09 PM
  2. Replies: 12
    Last Post: 05-26-2014, 01:32 PM
  3. [SOLVED] lookup a range of data then sum totals on another sheet in order
    By beitzy in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 01-23-2014, 06:53 PM
  4. [SOLVED] Excel Macro to lookup sheet name with a range of cells and paste in the reference sheet
    By mishaq in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-08-2013, 02:55 PM
  5. Lookup/Query Data from one Sheet/Range to another...Need Help
    By djtech2k in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 08-17-2012, 03:29 PM
  6. lookup particular value in different worksheets and take range to one sheet
    By privba in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-02-2012, 01:24 PM
  7. LOOKUP will work in this case?
    By omdkhaleel in forum Excel General
    Replies: 1
    Last Post: 02-11-2010, 12:14 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