0
Sub search()

Columns("J:K").Select
Selection.EntireColumn.Hidden = False

ActiveSheet.PivotTables("PivotTable15").PivotSelect "device[All]", xlLabelOnly _
    + xlFirstRow, True

Cells.Find(What:=InputBox("Please enter the PartID", "Search"), _
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

ActiveCell.Offset(0, 1).Select
Selection.ShowDetail = True

Selection.Copy
Sheets("interface").Select
Range("L501").Select
ActiveSheet.Paste

Columns("J:K").Select
Selection.EntireColumn.Hidden = True
Range("A2").Select




 End Sub

我的子按钮上有这段代码,但是当我取消显示的输入框时出现错误。错误是:“无法设置 Range 类的 ShowDetail 属性”。突出显示的错误是:

 Selection.ShowDetail = True
4

1 回答 1

0

错误的出现是因为它没有找到任何东西。您可以通过多种方式捕获错误,其中之一是:

Sub search()
dim sPartID as string
Columns("J:K").Hidden = False

ActiveSheet.PivotTables("PivotTable15").PivotSelect "device[All]", xlLabelOnly _
    + xlFirstRow, True

sPartID=InputBox("Please enter the PartID", "Search")
if len(sPartID)=0 then exit sub

Cells.Find(What:=sPartID, _
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False).Activate

ActiveCell.Offset(0, 1).ShowDetail = True

Selection.Copy Sheets("interface").Range("L501")

Columns("J:K").EntireColumn.Hidden = True
Range("A2").Select

End Sub
于 2013-07-29T04:57:59.110 回答