|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
把你的程序小改了一下。其中复制数据的注释掉了,自己按需要加进去吧。- Sub omg1()
- Dim c As Range, t, wb As Workbook, r&, i&, arr, firstAddress$
- t = InputBox("请输入一个客户编号")
- If t = "" Then Exit Sub
- On Error Resume Next
- Application.ScreenUpdating = False
- Set wb = Workbooks("B表格.xlsx")
- If wb Is Nothing Then
- Set wb = Workbooks.Open(ThisWorkbook.Path & "\B表格.xlsx")
- ThisWorkbook.Activate
- End If
- On Error GoTo 0
- r = wb.Sheets(1).[b65536].End(xlUp).Row
- arr = [a1].CurrentRegion
- For i = 2 To UBound(arr)
- If CStr(arr(i, 4)) = t Then
- r = r + 1: n = n + 1
- With wb.Sheets(1)
- ' .Cells(r, 5) = arr(i, 8)
- .Cells(r, 2) = arr(i, 2)
- ' .Cells(r, 6) = arr(i, 9)
- ' .Cells(r, 7) = arr(i, 10)
- ' .Cells(r, 25) = arr(i, 26)
- If arr(i, 26) <> "" Then .Cells(r, 2).Interior.ColorIndex = 6
- End With
- End If
- Next
- If n = 0 Then MsgBox "没有查到该客户,请重新输入": Exit Sub
- Application.ScreenUpdating = True
-
- End Sub
复制代码 |
|