Create a search box and then copy to new worksheet. Please help

Closed
ctran123 Posts 3 Registration date Wednesday January 21, 2015 Status Member Last seen March 3, 2015 - Mar 3, 2015 at 11:17 AM
Hello, this is what I have so far by searching online and it is not working :( It keeps sending me a message " Variable not defined "
Please help me !!! I really appreciate it.


The data is in Sheet3 and the textbox is inserted in Sheet4.
In Sheet4, insert a textbox (named as textbox1) and a command button (named as commandbutton1), the right click the commandbutton, select View Code, copy the following code then. Change the sheet name in the code where for sheet_search and sheet_paste.

Private Sub CommandButton1_Click()

Dim search_value As String

Dim loop_rows As Integer

Dim loop_i As Integer

Dim sheet_search As String

Dim sheet_paste As String

`Change the sheet name in the following two lines.

sheet_search = "Sheet3"

sheet_paste = "Sheet4"

search_value = TextBox1.Value

loop_rows = Sheets(sheet_search).UsedRange.Rows.Count

Sheets(sheet_search).Select

For loop_i = 2 To loop_rows

If Sheets(sheet_search).Cells(loop_i, 1) = search_value Then

Sheets(sheet_search).Rows(loop_i).Copy

Sheets(sheet_paste).Select

If IsNull(Sheets(sheet_paste).Cells(5, 1)) Then

Sheets(sheet_paste).Rows(5).Select

ActiveSheet.Paste

Else

' ActiveSheet.UsedRange.Rows(UBound(ActiveSheet.UsedRange.Value)).Row

Sheets(sheet_paste).Rows(Sheets(sheet_paste).UsedRange.Rows(UBound(ActiveSheet.UsedRange.Value)).Row + 1).Select

ActiveSheet.Paste

End If

End If

'loop_i = loop_i + 1

Next

End Sub
Related: