Help to correct code with textbox in form

sbv1986

Board Regular
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
[COLOR=#ff0000]Set ans1 = TextBox1.Value[/COLOR]
    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
 

sbv1986

Board Regular
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?
 

Fluff

MrExcel MVP, Moderator
Cross posted https://www.excelforum.com/excel-programming-vba-macros/1291828-help-to-set-value-from-textbox-then-copy-row-if-condition-is-meet-with-that-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.
 

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top