"Vlookup" and "Match" in VBA
- ©«¤l
- 65
- ¥DÃD
- 11
- ºëµØ
- 0
- ¿n¤À
- 83
- ÂI¦W
- 0
- §@·~¨t²Î
- Window 7
- ³nÅ骩¥»
- 2007
- ¾\ŪÅv
- 20
- µù¥U®É¶¡
- 2010-5-4
- ³Ì«áµn¿ý
- 2012-5-21
|
¥»©«³Ì«á¥Ñ am0251 ©ó 2011-6-27 18:14 ½s¿è
ÁÂÁÂHsieh¤j¤jªº¥X¤â¬Û§U......¥i¬OÁÙ¬O¤£¦æ.........,¥i¥H¦A§i¶D§Ú,§Ú¤S¿ù¦bþ¸Ì©O?¸U¤G¤À·PÁÂ!- Private Sub Start_Click()
- Dim x As Integer, y As Integer, z As Integer, S1 As Integer, S2 As Integer, myRowCount As Integer
- Dim ShipDate As Double
- Dim ItemName As String
- z = 2
- myRowCount = Range("A1").CurrentRegion.Rows.Count
- ShipDate = Format(Calendar1.Value, "d-mmm-yy")
- For i = 2 To myRowCount
- ItemName = Worksheets("Sheet1").Range("A" & z).Value
- x = Application.Match(ItemName, Sheet2.Range("A1:A" & myRowCount), 0)
- y = Application.Match(ShipDate, Sheet2.[B1:AF1], 0)
- S1 = Workbooks("Book1").Worksheets("Sheet2").Cells(x, y).Value
- S2 = Workbooks("Book1").Worksheets("Sheet1").Cells(z, 2).Value
- S1 = S1 + S2
- z = z + 1
- Next i
- Unload Me
- MsgBox "Done"
- End Sub
½Æ»s¥N½X |
|
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X
|
|
|
|
|
- ©«¤l
- 65
- ¥DÃD
- 11
- ºëµØ
- 0
- ¿n¤À
- 83
- ÂI¦W
- 0
- §@·~¨t²Î
- Window 7
- ³nÅ骩¥»
- 2007
- ¾\ŪÅv
- 20
- µù¥U®É¶¡
- 2010-5-4
- ³Ì«áµn¿ý
- 2012-5-21
|
¬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
|
|
|
|
|
- ©«¤l
- 65
- ¥DÃD
- 11
- ºëµØ
- 0
- ¿n¤À
- 83
- ÂI¦W
- 0
- §@·~¨t²Î
- Window 7
- ³nÅ骩¥»
- 2007
- ¾\ŪÅv
- 20
- µù¥U®É¶¡
- 2010-5-4
- ³Ì«áµn¿ý
- 2012-5-21
|
§¹¬üªº¸Ñ¨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
|
|
|
|
|
- ©«¤l
- 38
- ¥DÃD
- 19
- ºëµØ
- 0
- ¿n¤À
- 84
- ÂI¦W
- 0
- §@·~¨t²Î
- win7
- ³nÅ骩¥»
- office 2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- ¨Ó¦Û
- taichung
- µù¥U®É¶¡
- 2011-7-6
- ³Ì«áµn¿ý
- 2022-3-29
|
¥i¬d¬Ýexcel»¡©ú¤º¤½¦¡¬d¸ß |
|
|
|
|
|
|
- ©«¤l
- 56
- ¥DÃD
- 8
- ºëµØ
- 0
- ¿n¤À
- 81
- ÂI¦W
- 0
- §@·~¨t²Î
- Window7
- ³nÅ骩¥»
- OFFICE2010
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2011-6-25
- ³Ì«áµn¿ý
- 2016-1-17
|
¬Ý¤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- Public Function VLMatch(tt$, KK$, NN$, DALL As Range, dt As Range) As String
- Dim i%, j$, k As Boolean
- i = Evaluate("Match(kk, dt, 0)")
- j = Evaluate("VLookup(tt, DALL, i, 0)")
- k = Evaluate("IsNA(j)")
- If k = False Then
- VLMatch = NN
- Else
- VLMatch = j
- End If
-
- End Function
½Æ»s¥N½X
¦Û©w¸q¨ç¼Æ VLOOK+Match.rar (108.68 KB)
|
|
|
|
|
|
|
- ©«¤l
- 5923
- ¥DÃD
- 13
- ºëµØ
- 1
- ¿n¤À
- 5986
- ÂI¦W
- 0
- §@·~¨t²Î
- win10
- ³nÅ骩¥»
- Office 2010
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW°ò¶©
- µù¥U®É¶¡
- 2010-5-1
- ³Ì«áµn¿ý
- 2022-1-23
|
¦^´_ 28# Happkkevin - Public Function VLMatch(tt$, KK$, NN$, DALL As Range, dt As Range) As String
- 'Match §ä¨ìÈ«h¶Ç¦^¼Æ¦r,¨S§ä¨ìÈ«h¶Ç¦^¿ù»~È
- 'VLookup §ä¨ì¶Ç¦^¦r¦ê,¨S§ä¨ì¶Ç¦^¿ù»~È
- Dim i As Variant, j As Variant 'Åܼƻݳ]©w¬°Variant¸ê®Æ«¬ºA
- 'Variant¸ê®Æ«¬ºA¬O©Ò¦³¨S³Q©ú½T«Å§i¬°¥ô¤@¨ä¥L«¬ºA
- i = Application.Match(KK, dt, 0) 'vba¤¤¨Ï¥Î¤u§@ªí¨ç¼Æ-> Application.¤u§@ªí¨ç¼Æ
- '½Ð¬Ývba¤¤¥i¨Ï¥Îªº¤u§@ªí¨ç¼Æ
- j = Application.VLookup(tt, DALL, i, 0)
- '*** Evaluate("VLookup(tt, DALL, i, 0)")=[VLookup(tt, DALL, i, 0)]
- '¤£±µ¨üÅÜ¼Æ tt, DALL, i ***
- If IsError(j) Then 'j¶Ç¦^¿ù»~È
- VLMatch = NN
- Else: 'j¶Ç¦^¦r¦ê
- If j = "" Then VLMatch = NN Else VLMatch = j
- End If
- End Function
½Æ»s¥N½X |
|
|
|
|
|
|
- ©«¤l
- 56
- ¥DÃD
- 8
- ºëµØ
- 0
- ¿n¤À
- 81
- ÂI¦W
- 0
- §@·~¨t²Î
- Window7
- ³nÅ骩¥»
- OFFICE2010
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2011-6-25
- ³Ì«áµn¿ý
- 2016-1-17
|
¥»©«³Ì«á¥Ñ 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³\¤[®É¶¡×¥¿¥un¸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) |
|
|
|
|
|
|