+ Reply to Thread
Results 1 to 16 of 16

VBA code to Select Cell based on multiple criteria

  1. #1
    Registered User
    Join Date
    08-30-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    38

    VBA code to Select Cell based on multiple criteria

    I'm looking for a vba code to select the cell based on the 2 criteria's (1. search the string in column A and 2. search for a date number in row 4). basically i have a sheet which consists of employee names in column A and numbers (1 to 31, which is formula based) as a header in row 4. I have a userform with combobox & Calendar control. My query here is based on the employee name & date selected in userform, i want to select the cell in sheet for that employee.

    For Example: In the image if i want to choose Employee3 and date as 9, macro code should select the J8 cell.

    I've attached the sample file & code for reference.

    any help here is really appreciated !!

    Leave.PNG
    Userform.PNG
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA code to Select Cell based on multiple criteria

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code to Select Cell based on multiple criteria

    Another option...
    Please Login or Register  to view this content.
    Last edited by sintek; 11-28-2020 at 03:37 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  4. #4
    Registered User
    Join Date
    08-30-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: VBA code to Select Cell based on multiple criteria

    @Mumps1

    Thank you for taking your time to look into my query. I did a testing with the sample code provided. However, i see that the fnd variable is not selecting the desired combobox value choosen, instead it always selected the row 7 value.

    could you please look into this and provide me an alternate solution.

    thank you.!
    Last edited by ankamshetti.nagaraj; 11-30-2020 at 10:45 AM.

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: VBA code to Select Cell based on multiple criteria

    My pleasure.

  6. #6
    Registered User
    Join Date
    08-30-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: VBA code to Select Cell based on multiple criteria

    Hi,

    it is always selecting only one employee name. can you please look into it.

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code to Select Cell based on multiple criteria

    Have you tried post 3 that works with your sample file?

  8. #8
    Registered User
    Join Date
    08-30-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: VBA code to Select Cell based on multiple criteria

    Hi @sintek,

    thank you for your time and code. I tried testing with your code, it is selecting the cell next to the found employee name, but in the hidden columns. if you observe there are hidden columns and freezed at column A.

    thank you.

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code to Select Cell based on multiple criteria

    Nope, you are mistaken...it works as it should...
    Unless you are making use of a different file to the one uploaded in post 1

    Are you?

    Edit...Mumps1's code also works as it should...
    Last edited by sintek; 11-30-2020 at 11:12 AM.

  10. #10
    Registered User
    Join Date
    08-30-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: VBA code to Select Cell based on multiple criteria

    Hi Sinket,

    Nope, i am using the same file which i have uploaded. if you observe it is a month on month leave tracker, obviously i will be choosing the current month then in that case, the columns will get hide. so, at that instance if i use the code provided by you, it is selecting the cell adjacent to the employee name found in the january month only.

    Mumps1's code is selecting the first employee all the time. please do the needful.

    Thank you.

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code to Select Cell based on multiple criteria

    Nope...it does work...
    You need to ensure that the calendar selection of userform and sheet calendar is same...
    See result from selection...

    Result.png
    Last edited by sintek; 11-30-2020 at 12:27 PM.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code to Select Cell based on multiple criteria

    If you do not want to manually make the month change on sheet then this will suffice...
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    08-30-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: VBA code to Select Cell based on multiple criteria

    Hi Sintek,

    I tried your code with month selection as January & it works well, but when i move to the next month by clicking on the arrow button in the sheet, it doesn't give me the expected results. please see the image shared below. I've choose February month in the sheet, 3rd Feb in calendar and Employee 4 ideally it should select the Cell AI10, instead it selects D10. if you observe there are columns which gets hide automatically when ever you click on the right arrow in the sheet.

    Attachment 706535

    Thanks.

  14. #14
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code to Select Cell based on multiple criteria

    Oh okay, now I see...

    As I said Mumps code does work...
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    08-30-2012
    Location
    Hyderabad
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: VBA code to Select Cell based on multiple criteria

    Hi Sintek,

    Thank you, this code worked like charm! Really appreciated. Is there any option to restrict the employee to edit other employee leaves. only my manager should be able to edit all the employee leaves.

    Basically, i am looking for if Employee 1 opens this template only he/she should be able to edit/update his/her leaves, rest all employee leave details should be protected for editing. Only my manager should have access to update them.

    Thanks.

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,239

    Re: VBA code to Select Cell based on multiple criteria

    Is there any option to restrict the employee to edit other employee leaves. only my manager should be able to edit all the employee leaves.
    This is a new requirement and has no bearing on this thread...Time for a new one...

+ 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] VBA code to get the value of a cell based on multiple criteria
    By braun reivn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-26-2020, 07:56 PM
  2. Select a cell at random based on multiple selection criteria across multiple sheets.
    By scottyms in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-03-2016, 09:44 AM
  3. Replies: 6
    Last Post: 06-17-2014, 11:11 AM
  4. Select Max Date Based on Multiple Criteria with Wildcard Text
    By TxNyCa in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-28-2013, 02:34 PM
  5. Select multiple criteria based on check box selection and return all unique values.
    By TommyToe in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-21-2013, 09:14 AM
  6. Need code to select a range of cells based on criteria in column H
    By davekippen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-06-2011, 01:40 PM
  7. Replies: 1
    Last Post: 06-15-2006, 07:10 PM

Tags for this Thread

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