ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

"Vlookup" and "Match" in VBA

"Vlookup" and "Match" in VBA

§Ú¥­±`³£·|¥Î«Ü¦h"Vlookup" ¸ò "Match",¦pªG§Ú·Q¥ÎVBAªº¤è¦¡¼g¥X¨Ó,¸Ó«ç»ò°µ©O?
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

¥»©«³Ì«á¥Ñ Happkkevin ©ó 2011-7-17 12:00 ½s¿è
¦^´_  Happkkevin
GBKEE µoªí©ó 2011-7-17 08:45


GBKEE ª©¤j¡A¯uªº¬O¤Ó¼F®`Åo
¨C¨C§Úªá¤F³\¤[®É¶¡­×¥¿¥u­n¸g¹L¦¹³B¥ý¶iªº«ü¾É
¤£¥u°ÝÃD¸Ñ¨M¡A§óÅý§Ú¾Ç¨ì³\¦h
¦Ü©óVBA¥i¥Î¨ç¼Æ¤§«e§Ú¨S¦³½T»{¥u¬O if µo¥Í°ÝÃD¤~³B²z
»¡©ú¤¤ §Úªº³nÅéÃö©ó vlookup »P match ¨S¦³»¡©ú¡A¦ý§Ú·QÀ³¸Ó¬O»P¨ç¼Æ¬Û¦P
·PÁ§Aªº«ü¾É
­×¥¿¬°§Aªº»yªk¥[¤W­×¥¿ NN¿é¤J""§Y²Å¦X§Úªº»Ý¨D
=vlmatch($A2,E$1,"µL³]³Æ¸ê®Æ",³]³Æ²M³æ!$A$1:$B$20,³]³Æ²M³æ!$A$1:$B$1)

TOP

¦^´_ 28# Happkkevin
  1. Public Function VLMatch(tt$, KK$, NN$, DALL As Range, dt As Range) As String
  2.     'Match  §ä¨ì­È«h¶Ç¦^¼Æ¦r,¨S§ä¨ì­È«h¶Ç¦^¿ù»~­È
  3.     'VLookup   §ä¨ì¶Ç¦^¦r¦ê,¨S§ä¨ì¶Ç¦^¿ù»~­È
  4.     Dim i As Variant, j As Variant  'Åܼƻݳ]©w¬°Variant¸ê®Æ«¬ºA
  5.     'Variant¸ê®Æ«¬ºA¬O©Ò¦³¨S³Q©ú½T«Å§i¬°¥ô¤@¨ä¥L«¬ºA
  6.     i = Application.Match(KK, dt, 0)  'vba¤¤¨Ï¥Î¤u§@ªí¨ç¼Æ->  Application.¤u§@ªí¨ç¼Æ
  7.     '½Ð¬Ývba¤¤¥i¨Ï¥Îªº¤u§@ªí¨ç¼Æ
  8.     j = Application.VLookup(tt, DALL, i, 0)
  9.     '***   Evaluate("VLookup(tt, DALL, i, 0)")=[VLookup(tt, DALL, i, 0)]
  10.     '¤£±µ¨üÅÜ¼Æ tt, DALL, i   ***
  11.     If IsError(j) Then   'j¶Ç¦^¿ù»~­È
  12.         VLMatch = NN
  13.     Else:    'j¶Ç¦^¦r¦ê
  14.         If j = "" Then VLMatch = NN Else VLMatch = j
  15.     End If
  16. End Function
½Æ»s¥N½X

TOP

¬Ý¤F¤W­±ªº©«¤l¡A¹ï©ó¨ç¼Æ¨Ï¥Î©óVBA ÁÙ¬O¤@ª¾¥b¸Ñ
¤£ª¾¥i§_±N±`¥Îªº¨ç¼Æ²Õ¦X¹B¥Î©ó VBA §e²{¡A°t¦X¦Û©w¸q¨ç¼Æ¨Ï¥Î
¦ýÀ³¸Ó¬O¹ï©ó¸ê®Æ§ÎºAÁÙ¤£¤F¸Ñ¡A¦A¥[¤W¨ç¼Æªº¼gªk§ó¬O­è¥Î
©Ò¥H¼g¤F¤@­ÓÀ³¸Ó¬O¿ù»~¤£¤Ö¡A§ï¤F¼Æ¦¸³£¶Ã¤FÃÐ
¦pªþ¥ó¡A§Æ±æ¦³¥ý¶i¥i¥H¨ó§U¤@¤U¬Ý¬O§_¥i¦æ
¨ç¼Æ²Õ¦X¬°
=IF(ISNA(VLOOKUP($A2,³]³Æ²M³æ!$A$1:$B$20,MATCH(D$1,³]³Æ²M³æ!A$1:B$1,0),0)),"µL³]³Æ¸ê®Æ",(VLOOKUP($A2,³]³Æ²M³æ!$A$1:$B$20,MATCH(D$1,³]³Æ²M³æ!A$1:B$1,0),0)))
§Æ±æ§e²{
=vlmatch($A2,E$1,µL³]³Æ¸ê®Æ,³]³Æ²M³æ!$A$1:$B$20,³]³Æ²M³æ!$A$1:$B$1)
vlmatch ¬°¦Û©w¸q¨ç¼Æ¡A¥u»Ý¿é¤J $A2,E$1,µL³]³Æ¸ê®Æ,³]³Æ²M³æ!$A$1:$B$20,³]³Æ²M³æ!$A$1:$B$1§Y¥i
§ï¤F¼Æ¦¸¡A³Ì«á¿ù»~¡A¼g¤F¦p¤U
  1. Public Function VLMatch(tt$, KK$, NN$, DALL As Range, dt As Range) As String

  2. Dim i%, j$, k As Boolean
  3. i = Evaluate("Match(kk, dt, 0)")
  4. j = Evaluate("VLookup(tt, DALL, i, 0)")
  5. k = Evaluate("IsNA(j)")
  6. If k = False Then
  7.   VLMatch = NN
  8.   Else
  9.   VLMatch = j
  10.   End If

  11. End Function
½Æ»s¥N½X
¦Û©w¸q¨ç¼Æ VLOOK+Match.rar (108.68 KB)

TOP

¥i¬d¬Ýexcel»¡©ú¤º¤½¦¡¬d¸ß

TOP

.Cells(a.Row, k) = .Cells(a.Row, k) +d(a.Value)
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

§¹¬üªº¸Ñ¨M~~!!¤£¹L¥i¥H¦A±Ð§Ú¦h¤@­Ó¥\¯à¶Ü?´N¬O·Q¨C¦¸§â¸ê®Æ°e¨ì¥Ø¼Ð¦ì¸m®É¤£¥Î"="¦Ó¬O¬Û¥[,¨Ò¦p,"SHEET1" ªº"AAA"ªº¸ê®Æ¬O"1",¦ý¥Ø¼Ð¦ì¸m¥»¨Ó´N¦³"2"ªº¸Ü,¹B§@¤§«á´N¥i¥HÅܦ¨"3",¨º´N¬O§Úªº¥Ø¤F..ÁÂÁÂ!!
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¦^´_ 23# am0251
  1. Private Sub Start_Click()
  2. Dim mydate#
  3. mydate = Calendar1.Value
  4. Set d = CreateObject("Scripting.Dictionary")
  5. With Sheet1
  6. sh = .[E1] '¤u§@ªí¦WºÙ
  7. For Each a In .Range(.[A2], .Cells(.Rows.Count, 1).End(xlUp))
  8.    d(a.Value) = a.Offset(, 1).Value
  9. Next
  10. With Sheets(sh)
  11.   k = Application.Match(mydate, .Rows(1), 0)
  12.    If IsError(k) Then MsgBox "The day is not find!": Exit Sub
  13.       For Each a In .Range(.[A2], .Cells(.Rows.Count, 1).End(xlUp))
  14.          .Cells(a.Row, k) = d(a.Value)
  15.       Next
  16. End With
  17. End With
  18. Unload Me
  19. MsgBox "Done"
  20. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¬O³o¼Ëªº,§Úªº³]­p¬O·Q§â"SHEET1"ªº¸ê®Æ«ö¤é´Á,¦WºÙ,¨C­¶ªº¦WºÙ,©ñ¨ì¹ïÀ³ªº¦ì¸m,¥i±¤¥\¤O¤£°÷,¤d®t¸U¿ù,§Æ±æ¦U¦ì°ª¤â«üÂI¤@¤U~~ÁÂÁÂ!! test.rar (30.27 KB)
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¥»©«³Ì«á¥Ñ Hsieh ©ó 2011-6-26 22:54 ½s¿è

¦^´_ 21# am0251
¬JµM¤w¸g«Å§i¦¨DOUBLE«¬ºA
ShipDate = Format(Calendar1.Value, "d-mmm-yy")
³o¼Ë¤SÂন¤F¦r¦ê¡A·íµM«¬ºA¤£²Å
ª½±µShipDate =Calendar1.Value
¥u°w¹ï»yªk¸ÑÄÀ¡A¨ä¥L¤£¤F¸Ñ§Aªº¥Øªº¬O¬Æ»ò?µLªkµ¹§A¥ô¦ó·N¨£
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : ¤£­nÀH¤ß©Ò±ý¡A­nÀH¤ß±Ð¨|¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD