+ Reply to Thread
Results 1 to 17 of 17

Find row number from value in combobox by searching sheet

  1. #1
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Find row number from value in combobox by searching sheet

    I need to find the row number on a sheet by searching for a value from the combo box. I have created a calender that lists dates that are free in the combo box and then details need to put inputted in the same row. I've written this code and used a messagebox to test that the row is correct, but it just shows 0. This is the code i've written, not sure if im on the right lines..

    Please Login or Register  to view this content.
    Last edited by sabrinamay16; 12-29-2012 at 10:30 AM.

  2. #2
    Registered User
    Join Date
    12-27-2012
    Location
    Panama
    MS-Off Ver
    Excel 2007
    Posts
    90

    Re: Find row number from value in combobox by searching sheet

    I don't see value being assigned for the value r,

    so when i = r it doesn't get a value,

    if you meant to do r = i, it has to be done in the for loop because after the for loop the value of i disappears.

  3. #3
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Find row number from value in combobox by searching sheet

    Hello sabrinamay16,

    Welcome to the forum.

    When reading the forum rules perhaps you overlooked the one requiring code tags?
    All VBA code must be wrapped in code tags.

    Please edit your post to add them. Simply highlight all the lines of VBA code then press the button with the # symbol on it. Thanks.
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

  4. #4
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find row number from value in combobox by searching sheet

    Please Login or Register  to view this content.
    I've switched it round to this and it returns the value 0 still

  5. #5
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Find row number from value in combobox by searching sheet

    I would opt for using the FIND METHOD rather than looping.
    In the example code in the above link you would only need to use

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find row number from value in combobox by searching sheet

    I've had a look at the link and have changed my code to just this:
    Please Login or Register  to view this content.
    It returning and error saying 'run time error 91. object variable or with block variable not set.
    If i dont pick a value in the combox and leave it blank, it returns the value 2 in the message box..

  7. #7
    Valued Forum Contributor
    Join Date
    02-12-2011
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    818

    Re: Find row number from value in combobox by searching sheet

    The following works fine with me Sabrina.
    Please Login or Register  to view this content.
    Kind regards, Harry.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Find row number from value in combobox by searching sheet

    Is the combobox populated from a contiguous range?

    If it is then you could use the ListIndex to find the row.

    If it's not another way to find the row might be to use Application.Match.

    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  9. #9
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find row number from value in combobox by searching sheet

    The dates shown in the combobox are the only dates with blank cells to the right of them from the calendar sheet. i need code that finds the row that the date selected is in to then add data to the columns next to it

    I've tried that code but it returns an error 'subscript out of range'

  10. #10
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find row number from value in combobox by searching sheet

    I've changed it to this and i think it will work, but atm i tested that it returns the value from the combo box using msgbox and it returns blank each time! any clue why?? this is the code:
    Please Login or Register  to view this content.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Find row number from value in combobox by searching sheet

    That's because I spelt 'Calendar' kind of right.

  12. #12
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find row number from value in combobox by searching sheet

    haha I didn't notice it either! I've managed to get it to return the value of the combobox to search it and the code doesnt crash, but it doesnt show a messagebox or anything now

    Please Login or Register  to view this content.
    ive tried 'msgbox r' to see what it returns, but it crashes

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Find row number from value in combobox by searching sheet

    VBA/Excel can be funny when dealing with dates.

    Why not attach a workbook?

  14. #14
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find row number from value in combobox by searching sheet

    should say if in the code not ' f

  15. #15
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find row number from value in combobox by searching sheet

    can i not change it to search for the date as a string? could make it easier

    what do you mean by a workbook?

  16. #16
    Registered User
    Join Date
    12-27-2012
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    17

    Re: Find row number from value in combobox by searching sheet

    ooo wait can you attach your workbook here? i'm new to this..

  17. #17
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Find row number from value in combobox by searching sheet

    You do have an Excel workbook/file where you are using this code, I hope?

    I doubt using a string would work, unless the dates on the worksheet are strings.

+ 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