·µ»ØÊ×Ò³
µ±Ç°Î»ÖÃ: Ö÷Ò³ > Excel½Ì³Ì > Excel VBA½Ì³Ì >

EXCELÈçºÎʹÓÃVBAÒ»´ÎÂÞÁбíÖÐÈýÊ¡µÄÔ±¹¤ÐÕÃû£¿

ʱ¼ä:2012-07-19 16:12À´Ô´:Office½Ì³ÌѧϰÍø www.office68.com±à¼­:ÂóÌïÊØÍûÕß

ÇëÂÞÁГËÄ´¨Ê¡”¡¢“ºþÄÏÊ¡”¡¢“ºþ±±Ê¡”Èý¸öÊ¡·ÝÔ±¹¤µÄ×ÊÁÏ¡£

VBA´úÂëÈçÏ£º

EXCELÈçºÎʹÓÃ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

------·Ö¸ôÏß----------------------------
±êÇ©(Tag):excel excel2007 excel2010 excel2003 excel¼¼ÇÉ excel½Ì³Ì excelʵÀý½Ì³Ì excel2010¼¼ÇÉ
------·Ö¸ôÏß----------------------------
ÍƼöÄÚÈÝ
²ÂÄã¸ÐÐËȤ