excel 中如何用宏制作一个查询小模块 在EXCEL中设置一个查寻功能的宏,怎么写?
\u5982\u4f55\u5229\u7528EXCEL\u5b8f\u505a\u4e00\u4e2a\u5c0f\u578b\u7684\u6570\u636e\u5e93\u67e5\u8be2\u7cfb\u7edf\u8fd9\u4e2a\u5f88\u7b80\u5355\uff0c\u4ee3\u7801\u5982\u4e0b\uff1a
Sub C5C15_B3B13()
Dim Fo As Object, myName As String
Set Fo = Application.FileDialog(msoFileDialogFilePicker)
Fo.Title = "\u8bf7\u9009\u62e9\u60a8\u8981\u590d\u5236C5\uff1aC15\u6570\u636e\u7684\u6587\u4ef6\uff1a"
If Fo.Show = True Then myName = Fo.SelectedItems(1)
If myName = "" Then
MsgBox "\u60a8\u53d6\u6d88\u4e86\u6587\u4ef6\u9009\u62e9\uff0c\u6240\u4ee5\u672c\u6b21\u5904\u7406\u672a\u5b8c\u6210\uff0c\u5c06\u76f4\u63a5\u9000\u51fa", vbOKOnly + vbInformation
Exit Sub
End If
Dim wb as Workbook
For Each wb in Workbooks
if wb.Fullname = myName then Goto wbHasOpened
Next
set wb = workbooks.open(myname)
wbHasOpened:
Dim sh as worksheet
For each sh in wb.sheets
if sh.name = "Voice Quality" Then
[b3:B13] = sh.[c5:c15].value
Exit For
end if
Next
Msgbox "\u5904\u7406\u5b8c\u6210\uff01"
wb.close True
End Sub
\u7b2c\u4e00\u6b65\u6253\u5f00\u83dc\u5355\u4e2d\u7684\u89c6\u56fe->\u5de5\u5177\u7bb1->\u63a7\u4ef6\u5de5\u5177\u7bb1->\u70b9\u51fb\u4e00\u4e0b\u5de5\u5177\u7bb1\u4e2d\u7684\u547d\u4ee4\u6309\u94ae,\u7136\u540e\u5728\u4f60\u6307\u5b9a\u7684\u4f4d\u7f6e\u6309\u9f20\u6807\u5de6\u952e\u62c9\u4e00\u4e2a\u65b9\u6846\u521b\u5efa\u4e00\u4e2a\u547d\u4ee4\u6309\u94ae,\u7136\u540e\u53cc\u51fb\u8be5\u6309\u94ae\u8fdb\u5165VBA\u7f16\u8f91\u6a21\u5f0f,\u518d\u628a\u4e0b\u9762\u7684\u4ee3\u7801\u91cc\u5206\u9694\u7ebf\u4e4b\u95f4\u7684\u4ee3\u7801\u7c98\u8d34\u8fdb\u53bb,\u518d\u56de\u5230\u5de5\u4f5c\u8868,\u70b9\u51fb \u63a7\u4ef6\u5de5\u5177\u7bb1\u4e2d\u7684\u9000\u51fa\u8bbe\u8ba1\u6a21\u5f0f.\u518d\u70b9\u51fb\u8be5\u6309\u94ae\u5c31\u53ef\u4ee5\u8fd0\u884c\u8fd9\u4e2a\u5b8f\u4e86
Private Sub CommandButton1_Click()
'-------------\u5206\u5272\u7ebf----------
Dim Rng As Range, AA As String
Dim Irng As Range
endcol = [iv1].End(xlToLeft).Column
endrow = Range("B65536").End(xlUp).Row
Set Irng = Range(Cells(1, 1), Cells(endrow, endcol))
AA = InputBox("\u8bf7\u8f93\u5165\u8981\u67e5\u627e\u7684\u5185\u5bb9:")
If AA "" Then
Set Rng = Irng.Find(AA, LookAt:=xlPart)
If Not Rng Is Nothing Then Rng.Select Else MsgBox "\u6ca1\u627e\u542b\u6709\u6307\u5b9a\u5185\u5bb9\u7684\u5355\u5143\u683c!"
End If
,---------\u5206\u5272\u7ebf---------
End Sub
Cells.Find(What:=[A1], After:=ActiveCell).Activate
End Sub
根据A1中输入的内容,在整个当前工作表中查找,其实就是EXCEL本身的查找功能,只是没有调出那个对话框而已。
思路是这样的。比如在输入框中输入客户的名称,然后程序根据名称在客户名列一行行往下对比。如果相同则选定该单元格即。
对比。选定。
用筛选功能比较好,筛选“包含 上海“
扩展阅读:宏的作用和使用方法 ... 如何取消表格录制js宏 ... excel宏入门教程图解 ... 怎样取消宏的工作表 ... wlk猎人一键输出宏 ... 宏制作教程 ... 宏程序编程口诀 ... excel宏新手入门教程 ... 在excel中使用宏制作表格 ...