+ Reply to Thread
Results 1 to 6 of 6

Using RANGE to find a spreadsheet record based on a value in a column

Hybrid View

  1. #1
    Registered User
    Join Date
    01-06-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    10
    Posts
    39

    Using RANGE to find a spreadsheet record based on a value in a column

    I've spent hours, cannot solve this so hopefully someone can help. I've tried to simplify the problem from the original xlsm file.

    There is a single spreadsheet containing a list of clinician names. Column A is a RECORD NUMBER (unique integer) for a clinician, Column B is the DISCIPLINE of the clinician (WCC, CNE, etc.), Column C is the clinician's NAME, Column D is the DATE ADDED of the record and Column E is the STATUS (ACTIVE, INACTIVE) of the record.

    The form to start this simple application is frmStart. Select one of the five disciplines and click "GO". This opens frmClinician and loads the listbox in the form with all the clinicians from the spreadsheet for the selected discipline.

    The form allows you to enter new names into the spreadsheet or modify the status of clinicians already entered in the spreadsheet.

    The process for entering new names works. No problem there.

    The problem is when selecting an existing name in the listbox so I can modify the status of the selected clinician. The problematic code is in the lstClinicians_Click() subroutine. I can get the index number of the selected clinician from the listbox. I can get the record number of the selected clinician from the spreadsheet. I'm trying to use the record number in the RANGE method to get the row number of the selected clinician from the spreadsheet so I can update the status of that clinician in that row.

    I have the line of code with the RANGE method commented out right now, but when you remove the comment and then try to select a clinician from the listbox, i get the error.

    I have spent hours trying to get this to work. My give up. can you help, please?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,983

    Re: Using RANGE to find a spreadsheet record based on a value in a column

    Add the following

    Dim shRec as Long
    
    'update the checkbox value in the spreadsheet
                shrec = Application.Match(iRecordNo, Sh.Range("$A$1:$A$100"), 0)
                If .chkActive.Value = True Then Sh.Cells(shrec, 5) = "ACTIVE" Else Sh.Cells(shrec, 5) = "INACTIVE"
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  3. #3
    Registered User
    Join Date
    01-06-2020
    Location
    Vancouver, Canada
    MS-Off Ver
    10
    Posts
    39

    Re: Using RANGE to find a spreadsheet record based on a value in a column

    I was actually hoping to discover how that single line of code should be modified to get the row number:

    iRowNo = Sh.Range("A:A").Find(What:=iRecordNo, LookAt:=xlWhole).Row 'SHOULDN'T THIS get the spreadsheet row number?

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Using RANGE to find a spreadsheet record based on a value in a column


    The red codeline in my previous post crashes on my side …


    Quote Originally Posted by vancouver_ron View Post
    I was actually hoping to discover how that single line of code should be modified to get the row number:

    iRowNo = Sh.Range("A:A").Find(What:=iRecordNo, LookAt:=xlWhole).Row 'SHOULDN'T THIS get the spreadsheet row number?
    Many useless things within the code …
    This codeline should be totally useless just storing the original row # in an additional listbox hidden column and as it is no crash on my side !

    Anyway according to the Macro Recorder and VBA help this works too on my side :
    iRowNo = ActiveSheet.UsedRange.Columns(1).Find(iRecordNo, , xlValues, xlWhole).Row
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 08-18-2023 at 11:51 PM.

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,983

    Re: Using RANGE to find a spreadsheet record based on a value in a column

    You need the change I gave in this macro:

    Private Sub cmdSave_Click()

    Otherwise status is not changed.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Using RANGE to find a spreadsheet record based on a value in a column


    • In the Refresh_CliniciansListbox procedure put this codeline in comment : .ColumnWidths = "20,0,200,0,100"

    • As you use ADODB on an opened workbook you may have some strange behavior, a classic well known issue …

+ 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. Select the record in a spreadsheet that matches the selected record in a listbox control
    By vancouver_ron in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2022, 11:50 AM
  2. [SOLVED] I have a record in cell A, I want to find it in a range of records...
    By tai8 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 06-13-2017, 11:54 AM
  3. Create button on spreadsheet when clicked record date stamp in the next column
    By HBHB in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-02-2013, 06:52 PM
  4. Replies: 20
    Last Post: 11-15-2012, 09:32 PM
  5. Replies: 2
    Last Post: 08-17-2005, 04:05 PM
  6. Replies: 1
    Last Post: 05-27-2005, 06:05 PM
  7. Replies: 0
    Last Post: 05-27-2005, 05:05 PM

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