Search not working now?

BarefootPaul

Board Regular
Joined
Jul 21, 2011
Messages
54
I wrote this code to search for a value in a column and then update the corresponding columns in that row, based on data entered into a userform. I swear it worked last week and now it isn't. Here is the code:

Code:
Private Sub cmdUpdate_Click()
    ActiveWorkbook.Sheets("Clients").Activate
    Range("C1").Select
    Do
    If ActiveCell.Value <> txtMaineCare.Value Then
        ActiveCell.Offset(1, 0).Select
    End If
    Loop Until ActiveCell.Value = txtMaineCare.Value Or ActiveCell.Value = ""
        If ActiveCell.Value = "" Then
            MsgBox ("There is no referral for this client.")
        Else
            ActiveCell.Offset(0, 9) = txtDOA.Value
            ActiveCell.Offset(0, 10) = cboResProgram.Value
            ActiveCell.Offset(0, 11) = cboPlacingAgency.Value
            If cboPlacingAgency.Value = "Other (specify)" Then
                txtPlaceOther.Enabled = True
                txtPlaceOther.SetFocus
                ActiveCell.Offset(0, 12) = txtPlaceOther.Value
            End If
            ActiveCell.Offset(0, 13) = txtGAFAdmit.Value
            ActiveCell.Offset(0, 14) = txtDischargePlan.Value
        End If
    Range("C1").Select
 
End Sub

It is suppossed to search column C until it finds the match, but even though I can can see that it is a match, it keeps telling me there is no match and the MsgBox to enter a referral comes up. Any suggestions would be helpful.

Thanks,
BarefootPaul
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
No need to physically activate sheets and select cells to find a value nor update the found row:

Code:
Private Sub cmdUpdate_Click()
Dim vFIND As Range

On Error Resume Next
With ActiveWorkbook.Sheets("Clients")
    Set vFIND = .Range("C:C").Find(txtMaineCare.Value, LookIn:=xlValues, LookAt:=xlWhole)
    If vFIND Is Nothing Then
        MsgBox ("There is no referral for this client.")
    Else
        vFIND.Offset(0, 9) = txtDOA.Value
        vFIND.Offset(0, 10) = cboResProgram.Value
        vFIND.Offset(0, 11) = cboPlacingAgency.Value
        If cboPlacingAgency.Value = "Other (specify)" Then
            txtPlaceOther.Enabled = True
            txtPlaceOther.SetFocus
            vFIND.Offset(0, 12) = txtPlaceOther.Value
        End If
        vFIND.Offset(0, 13) = txtGAFAdmit.Value
        vFIND.Offset(0, 14) = txtDischargePlan.Value
    End If
End With
    
End Sub


The most common thing that makes strings not match that appear they should are hidden spaces in the data column or in the search string.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top