Excelpopup应用程序input框(searchfunction)

我试图创build一个popup框来search第二列的特定值,因为我仍然是新的vba编码,我只能通过谷歌search做到这一点。

我想要做的是(所有这些都是在macros中完成的),find一个确定的值,然后当程序find一定的值,它会复制整个行的值,并粘贴到一个excel中的新工作表(具有相同的标题)

这是迄今为止的代码。

Sub macrotest() x = 2 Do While Cells(x, 1) <> "" If Cells(x, 2) = "TEST" Then Worksheets("Sheet1").Rows(x).Copy Worksheets("Sheet2").Activate erow = Sheet2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row ActiveSheet.Paste Destination:=Worksheets("Sheet2").Rows(erow) End If Worksheets("Sheet1").Activate x = x + 1 Loop End Sub 

在这里输入图像说明

正如你从上面看到的那样,我正试图把圆圈的行复制到一个新的表格中。

就像我在上面的评论中提到的那样,你可以使用Autofilter来做到这一点。 与在这里提到的代码不同,您可以使用InputBox来获取搜​​索文本

在那个链接strSearch = "Clarke, Matthew"是硬编码。 现在你可以使用下面的代码来获得你自己的strSearch

 Sub Sample() Dim strSearch strSearch = Application.InputBox("Please enter the search string") If strSearch <> False And Len(Trim(strSearch)) <> 0 Then Debug.Print strSearch ' '~~> Rest of the code ' End If End Sub