Help to correct code with textbox in form

sbv1986

Board Regular
Joined
Nov 2, 2017
Messages
87
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
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
you SET with objects.
TEXTBOX is an object ,but values are not, so:

ans1 = txtbox1.value
 
Upvote 0
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?
 
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...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.
 
Upvote 0

Forum statistics

Threads
1,213,491
Messages
6,113,963
Members
448,536
Latest member
CantExcel123

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