这个网站的新手,但是是excel自我思考的中级用户。 我有一本约15张的工作簿。 我正在寻找一段VBA代码,用户可以在excel中单击命令按钮以打开该框,然后输入他们要查找的参考号。到目前为止,我已经弄清楚了那部分。这是我在“搜索”代码中需要帮助的地方
一旦他们单击搜索,我希望VBA代码在每个工作表的第2行中搜索该值,一旦找到就去查找它。就这些。
我浏览了不同的网站,但似乎找不到简单的答案。
先谢谢了。 迪兹
答案 0 :(得分:0)
我将假设您可以为按钮,输入框编写代码,并且可以准备一个名为“ RefNum”的字符串变量,该变量包含一个字符串,该字符串可以在工作簿。
其余的代码片段如下所示:
Dim Sh as Worksheet, FoundIt as Range
For Each Sh in Activeworkbook.Worksheets Set FoundIt = Sh.Rows(2).Find(RefNum) ' Returns cell in Row 2 with the refnum If FoundIt IS Nothing Then Next Sh ' If not found, on to next sheet Sh.Activate ' If the RefNum WAS found, go to that sheet FoundIt.Activate ' And then to that cell Exit Sub ' Or perhaps just exit the For Each loop ' if you have other things to do at there Next Sh