DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Visual Basic 4 / 5 / 6 (http://www.daniweb.com/forums/forum4.html)
-   -   Use TaxtBox value in Find function in VBA (http://www.daniweb.com/forums/thread119694.html)

glfnfvr Apr 17th, 2008 7:36 pm
Use TaxtBox value in Find function in VBA
 
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.

cometburn Apr 17th, 2008 8:44 pm
Re: Use TaxtBox value in Find function in VBA
 
Why not use a date picker instead?

Jx_Man Apr 17th, 2008 11:23 pm
Re: Use TaxtBox value in Find function in VBA
 
# 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

glfnfvr Apr 18th, 2008 12:57 am
Re: Use TextBox value in Find function in VBA
 
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!


All times are GMT -4. The time now is 5:07 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC