excel查找一个值并复制到剪切板

Private Sub CommandButton1_Click()
Dim c As Range
jieguo = TextBox1.Value
‘jieguo = Application.InputBox(prompt:=”请输入要查找的值:”, Title:=”查找”, Type:=2)
If jieguo = “False” Or jieguo = “” Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
With ActiveSheet.Cells
Set c = .Find(jieguo, , , xlWhole, xlByColumns, xlNext, False)
If Not c Is Nothing Then
p = c.Address
Do ‘查找下一个
c.Interior.ColorIndex = 4

q = q & c.Address & vbCrLf

‘ Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> p
End If
End With
‘MsgBox “查找数据在以下单元格中:” & vbCrLf & vbCrLf & q, vbInformation + vbOKOnly, “查找结果”

‘Application.DisplayAlerts = True
a = “A” & c.Row & “:” & “F” & c.Row ‘复制A—F单元格到剪切板
ActiveSheet.Range(a).Select ‘选中单元格
ActiveSheet.Range(a).Copy ‘复制单元格到剪切板
‘ ActiveSheet.Range(a).Active ‘复制单元格到剪切板
Application.ScreenUpdating = True ‘屏幕刷新
ActiveSheet.Range(a).Select ‘选中单元格
End Sub

 

 » 本站地址:http://www.gomoth.com

标签: