- ©«¤l
- 9
- ¥DÃD
- 1
- ºëµØ
- 0
- ¿n¤À
- 15
- ÂI¦W
- 0
- §@·~¨t²Î
- xp
- ³nÅ骩¥»
- office 2003
- ¾\ŪÅv
- 10
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2012-12-5
- ³Ì«áµn¿ý
- 2019-6-6
|
[µo°Ý] §ä¤F¦n´X¤Ñ §ä¤£¥X¿ù»~,½Ð¨ó§U?
¥»©«³Ì«á¥Ñ GBKEE ©ó 2013-9-19 13:14 ½s¿è
§Ú¦b"main"¤u§@ªíªºA2Àx¦s®æ(§Ú©w¸q¥¦¬°product)¿é¤J¤@Ó²£«~¥N¸¹,«h¦b"main"¤u§@ªíªºrange("C2:C20")·|¦Û°ÊÅã¥Ü¸Ó²£«~©Ò»Ýªºì§÷®Æ¥N¸¹
ì²z¬O§Ú±N"main"¤u§@ªíªºrange("C2:C20")³]¦¨°}¦C¨ç¼Æ(=Sample(product)),³oÓ¨ç¼Æ·|¨ì"material"¤u§@ªíªºAÄæ¥h´M§ä»P"main"¤u§@ªíC2Àx¦s®æ¦r¦ê¬Û¦PªºÀx¦s®æ,·í§ä¨ì«á·|±N¹ïÀ³ªº"material"¤u§@ªíªºBÄæÀx¦s®æ¸ê®ÆÀx¦s¦¨°}¦C,³Ì«á¦A¦^¶Çµ¹Sample
§Ú°»´úªºµ²ªG,¿ù»~¬O¦bfindnext¤W,·í²Ä¤@¦¸¥Hfind§ä¨ì®É,½T¹ê¬O¦b$A$19Àx¦s®æ¤W,¦ý¬O±µ¤U¨Óset rng=.findnext(rng)ªºµ²ªG,«o©lrngÅܦ¨nothing?(¥¿±`À³¸Ó¬O$A$20¤~¹ï)
µ{¦¡½X¦p¤U:
Public Function Sample(product As Variant) As Variant
Application.Volatile
Dim oRange As Range
Dim rng As Range
Dim ws As Worksheet
Dim ExitLoop As Boolean
Dim FoundAt As String
Dim temp(18) As Variant
Dim i As Long
Dim MySearch As Variant
On Error GoTo Err
If TypeName(product) = "String" Then
MySearch = Range(product).Value
ElseIf TypeName(product) = "Range" Then
MySearch = product.Value
End If
With Sheets("material").Columns("A")
Set rng = .Find(What:=MySearch)
If Not rng Is Nothing Then
FirstAddress = rng.Address
Do
temp(i) = rng.Offset(0, 1).Text
Set rng = .FindNext(rng) '¨ç¼Æ°õ¦æ¨ì³o¸Ì®É,·|¥X¿ù
'¸g°»¿ù,«e±²Ä¤@Ófind§ä¨ìªº¦ì¸m$A$19¨S¿ù
'¥»¦¸ªºfindnext°õ¦æ«á,rngÅܦ¨nothing
'¦ý¥¿½Tªº¦ì¸mÀ³¸Ó¬O$A$20
'If rng Is Nothing Then Exit Do
i = i + 1
Loop While Not rng Is Nothing And rng.Address <> FirstAddress
End If
End With
Sample = temp
Set rng = Nothing
Exit Function
Err:
Set rng = Nothing
MsgBox Err.Description
Sample = "N/A"
End Function |
|