Results 1 to 5 of 5

Thread: Help to correct code with textbox in form
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    Board Regular
    Join Date
    Nov 2017
    Posts
    72
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Help to correct code with textbox in form

    Hi all
    I want to check value in textbox1 in form(CDKT) with sheet("nb","ngb"). If found will copy row to sheet(ky1) and Ihave code below
    Code yelow at line: Set ans1 = TextBox1.Value
    And have VBA notice: "Object require"

    Please help me correct this code, thanks
    Code:
    Sub Filter()Application.ScreenUpdating = False
    Sheets("ky1").Cells.clear
    
    
    Dim Lastrowa1 As Long, Lastrowa2 As Long, Lastrow1 As Long, Lastrow2 As Long
    Dim ans1 As Long
    
    
    Lastrowa1 = Sheets("nb").Cells(Rows.Count, "A").End(xlUp).Row
    Lastrowa2 = Sheets("ngb").Cells(Rows.Count, "A").End(xlUp).Row
    Lastrow1 = Sheets("ky1").Cells(Rows.Count, "A").End(xlUp).Row
    
    CDKT.Show
    Set ans1 = TextBox1.Value
        With Sheets("nb").Range("A1:A" & Lastrowa1)
            .AutoFilter Field:=1, Criteria1:="*" & ans1 & "*", Operator:=xlOr, Criteria2:=ans1
            .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Copy Worksheets("ky1").Range("A" & Lastrowd + 1)
            .AutoFilter
            .AutoFilter Field:=1, Criteria1:="*" & ans2 & "*", Operator:=xlOr, Criteria2:=ans2
            .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Copy Worksheets("ky1").Range("A" & Lastrowd + 1)
            .AutoFilter
        End With
    Application.ScreenUpdating = True
    End Sub

  2. #2
    Board Regular ranman256's Avatar
    Join Date
    Jun 2014
    Location
    Kentucky
    Posts
    1,775
    Post Thanks / Like
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to correct code with textbox in form

    you SET with objects.
    TEXTBOX is an object ,but values are not, so:

    ans1 = txtbox1.value

  3. #3
    Board Regular
    Join Date
    Nov 2017
    Posts
    72
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to correct code with textbox in form

    Quote Originally Posted by ranman256 View Post
    you SET with objects.
    TEXTBOX is an object ,but values are not, so:

    ans1 = txtbox1.value
    Thanks for your reply but there's sill mistake Object require - 424.

    Another infomation with my workbook that there have 03 form with name: CDKT, form control and form input. Is there any problem if my path is not right?

  4. #4
    MrExcel MVP
    Moderator
    Fluff's Avatar
    Join Date
    Jun 2014
    Location
    Chippenham
    Posts
    29,068
    Post Thanks / Like
    Mentioned
    483 Post(s)
    Tagged
    48 Thread(s)

    Default Re: Help to correct code with textbox in form

    Cross posted https://www.excelforum.com/excel-pro...hat-value.html

    While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
    This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
    - Posting Data try one of these tools
    - Posting guidelines, forum rules and terms of use
    - Read the FAQs

    Running Office 365 on Win 10

  5. #5
    Board Regular
    Join Date
    Nov 2017
    Posts
    72
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Help to correct code with textbox in form

    Oh sorry @Fluff, this problem has solved./.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •