ÇëÂÞÁГËÄ´¨Ê¡”¡¢“ºþÄÏÊ¡”¡¢“ºþ±±Ê¡”Èý¸öÊ¡·ÝÔ±¹¤µÄ×ÊÁÏ¡£
VBA´úÂëÈçÏ£º
Sub test()
'¶¨Òå±äÁ¿
Dim rng As Range, RngTemp As Range, firstAddress As String
Dim i As Byte, findCell As Range, sh As Worksheet, shtname As String
'½«²éÕÒµÄÄ¿±êÉèÖÃΪC2µ¥Ôª¸ñµ½CÁÐ×îºóÒ»¸ö·Ç¿Õµ¥Ôª¸ñ¸³Óè±äÁ¿Îªrng
Set rng = Range([C2], Cells(Rows.Count, "C").End(xlUp))
'Ñ»·¸³Óè²éÕÒÊý×éµÄÿһ¸öÔªËØ
For i = 0 To UBound(Array("ËÄ´¨Ê¡", "ºþÄÏÊ¡", "ºþ±±Ê¡"))
'¿ªÊ¼²éÕÒÊý¾Ý£¬°´Öµ¾«È·²éÕÒ£¬²»Çø·Ö´óСд
Set RngTemp = rng.Find(What:=Array("ËÄ´¨Ê¡", "ºþÄÏÊ¡", "ºþ±±Ê¡")(i), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
' Èç¹ûÕÒµ½Ä¿±ê£¬Ôò¸³Óè¸ÃÄ¿±êµÄµ¥Ôª¸ñµØÖ·¸øfirstAddress
If Not RngTemp Is Nothing Then
firstAddress = RngTemp.Address
Do
'±äÁ¿findCellûÓгõʼ»¯£¬ÔòÐèÒª³õʼ»¯£¬·ñÔòºÏ²¢²éÕÒµ½µÄÊýÖµ
If findCell Is Nothing Then
Set findCell = RngTemp
Else
Set findCell = Union(findCell, RngTemp)
End If
'²éÕÒÏÂÒ»¸ö
Set RngTemp = rng.FindNext(RngTemp)
'Ñ»·µ½²»ÎªµÚÒ»¸öÕÒµ½µÄÄ¿±êµØַΪֹ
Loop While RngTemp.Address <> firstAddress
End If
Next i
'Èç¹û²éÕÒµÄÄÚÈݲ»Îª¿Õ£¬ÔòÑ¡Ôñ²éÕÒµ½ÄÚÈÝËùÔÚÐУ¬·ñÔòÏÔʾÌáÐÑ
If Not findCell Is Nothing Then
findCell.EntireRow.Select
Else
MsgBox "ûÓÐÕÒµ½·ûºÏÌõ¼þµÄÊý¾Ý!"
Exit Sub
End If
'·ÀÖ¹´íÎó
On Error Resume Next
'°Ñµ±Ç°¹¤×÷±íµÄÃû³Æ¸³Óèshtname
shtname = ActiveSheet.Name
Set sht = Sheets("²éѯ½á¹û")
'Èç¹û²»´æÔÚ²éѯ½á¹û±í£¬ÔòÌí¼ÓÒ»¸ö“²éѯ½á¹û”¹¤×÷±í
If Err.Number <> 0 Then
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "²éѯ½á¹û"
Else
Sheets(Sheets.Count).Cells.Clear
End If
Sheets(shtname).Select
Selection.Copy Sheets(Sheets.Count).[A1]
End Sub |