I am trying to write a code that asks for a date in a user form text box and then takes that date and looks for it in a range. Once it finds that date I want to enter the data from the second text box in a cell on the same row. I can't seem to get the find function to work using the textbox value. Can anyone help me figure out a way to make this happen? If you need a better explanation of the problem/desired result please let me know! Thanks in advance for any help you can provide.

Recommended Answers

All 3 Replies

Why not use a date picker instead?

# To add a Date Time Picker control, on the Toolbox, click the More Controls button
# Scroll down in the list of controls, click Microsoft Date and Time Picker 6.0 (SP4), and click the form.
see this tutorial

commented: great link +1
commented: Yesh +1

Thanks for the reply. I got the problem resolved using the following code:

Private Sub OK_Click()

Application.ScreenUpdating = False

    ActiveWorkbook.Sheets("Amortization Table").Activate
       
    Range("C14").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    ActiveCell.Offset(0, 1).Select
    Selection.PasteSpecial Paste:=xlPasteValues
    Selection.NumberFormat = "m/d/yyyy"
    
    Dim rFound As Range

    On Error Resume Next
    With Sheets("Amortization Table")
        Set rFound = .Columns(4).Find(What:=TextBox1.Value, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
            xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
            , SearchFormat:=True)

    On Error GoTo 0
        If Not rFound Is Nothing Then Application.Goto rFound, True
        
    End With
        
    ActiveCell.Offset(0, 7) = TextBox2.Value
        
    Range("A1").Select
    
    Call UserForm_Initialize
    frmPrinPmt.Hide
    ActiveWorkbook.Sheets("Enter Data").Activate
    Range("A1").Select
    
End Sub

the problem was with the find section, but when I added the Dim rfound As Range and the With and error handling it worked fine.

While this works I will still try the date picker to see if it would be better/easier. Thanks again for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.