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

"Vlookup" and "Match" in VBA

ÁÂÁ«ü±Ð~~!!·Pı¥\¤O´£ª@¤F¤£¤p!!
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2011-6-23 13:46 ½s¿è

¦^´_ 8# am0251
Sub test()
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim ItemName As String
z = 2
Do While Range("A" & z).Value <> ""
'ItemNam = Worksheets("Sheets1").Range("A" & z).Value       '§AªºªþÀɤ¤¨S¦³Sheets1¤u§@ªí
'x = Evaluate("MATCH(""ItemNam"",Sheet(Sheets2)!A:A,0)")    §AªºªþÀɤ¤¨S¦³Sheets2¤u§@ªí
'x = Application.WorksheetFunction.Match(Worksheets("Sheets1").Range("A" & z).Value, Sheets("Sheets2").Range("A:A")) '¦p¤Wªº¿ù»~
ItemNam = Worksheets("Sheet1").Range("A" & z).Value
x = Evaluate("MATCH(""" & ItemNam & """,Sheet2!A:A,0)")   'ItemNam¬OÅܼƭn¥Î&¨Ó³s±µ
x = Application.WorksheetFunction.Match(Worksheets("Sheet1").Range("A" & z).Value, Sheets("Sheet2").Range("A:A"))
Debug.Print x, y
z = z + 1
Loop
End Sub

TOP

¥»©«³Ì«á¥Ñ am0251 ©ó 2011-6-23 15:03 ½s¿è

¦pªG§Ú·Q§âÅܼÆ"y"ªº­Èµ¥©ó,§ÚªºUserFrom ¤ºªº Calendar ªº­È,¥i¬O§Ú¼g¤F"y = Calendar1.Value"¥X¨Óªºµ²ªG¬O"1/¤»¤ë/2011 ",§ÚªºÄݩʤw¸g§ï"­^¤å(²µu)"ªº¤F,­n¦b­þ¸Ì¥i¥H§ï¦¨"1-Jun-11"©O?
¦]¬°§Ú­n§â"x" "y"Åܦ¨Cells(x,y)ªºÚµ¼Ð,"x"´N¬OItemName,"y"´N¬O¤é´Á,¦pB2="1-Jun-11"; C2="2-Jun-11"............¦³¥i¯à°µªº¨ì¶Ü?
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

y = Format(Calendar1.Value, "d-mmm-yy")
MsgBox y

TOP

¤£¦n·N«ä......§Ú¤S¥¢±Ñ¤F...... Book1.rar (22.21 KB)
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

Cells(x, y)¸Ì­±ªºx,y³£¥²¶·¬O¼Æ¦r
¤£¯à¬O¤é´Á¡C

TOP

¥»©«³Ì«á¥Ñ am0251 ©ó 2011-6-24 15:36 ½s¿è

ÁÂÁ«üÂI,¤w§ï¦n¤F,¥i¬O.......ÁÙ¬O¤£¦æ......... Book1.rar (23.12 KB)

Book1.rar (23.12 KB)

50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

­è¦n¦³§Q¥Î¨ì~~·PÁÂoobird
Private Sub CommandButton1_Click()
Dim x As Integer, y As Integer, z As Integer, ItemName As String
z = 6
Do While Range("N" & z).Value <> ""
ItemNam = Sheet3.Range("N" & z).Value
Sheet3.Range("S" & z).Value = Application.VLookup(ItemNam, Sheet4.[A1:B29], 2, 0)
z = z + 1
Loop

End Sub

TOP

¥»©«³Ì«á¥Ñ am0251 ©ó 2011-6-25 14:39 ½s¿è

¤£¦n·N«ä,¤pªº¨S¬ÝÀ´....³o¬O§Úªºµ{§Ç
  1. Private Sub Start_Click()

  2. Dim x As Integer, y As Integer, z As Integer, S1 As Integer, S2 As Integer, myRowCount As Integer
  3. Dim ShipDate As Date
  4. Dim ItemName As String

  5. z = 2

  6. myRowCount = Range("A1").CurrentRegion.Rows.Count

  7. ItemName = Worksheets("Sheet1").Range("A" & z).Value

  8. ShipDate = Format(Calendar1.Value, "d-mmm-yy")

  9. For i = 2 To myRowCount

  10. x = Application.Match(ItemName, Sheet2.["A1", "A" & myRowCount], 0)
  11. y = Application.Match(ShipDate, Sheet2.[B1:AF1], 0)


  12. S1 = Workbooks("Book1").Worksheets("Sheet1").Cells(z, 2).Value
  13. S2 = Workbooks("Book1").Worksheets("Sheet2").Cells(x, y).Value

  14. S2 = S2 + S1

  15. z = z + 1

  16. Next i

  17. Unload Me

  18. MsgBox "Done"

  19. End Sub
½Æ»s¥N½X
50 ¦r¸`¥H¤º
¤£¤ä«ù¦Û©w¸q Discuz! ¥N½X

TOP

¥»©«³Ì«á¥Ñ Hsieh ©ó 2011-6-25 18:51 ½s¿è

¦^´_ 19# am0251
x = Application.Match(ItemName, Sheet2.["A1", "A" & myRowCount], 0)
³o¬O¿ù»~»yªk¡A§ï¬°
x = Application.Match(ItemName, Sheet2.Rnage("A1:A" & myRowCount), 0)

¤é´Á¦b¤u§@ªí¤º³Qµø¬°Double¸ê®Æ«¬ºA
©Ò¥HÀ³«Å§i¬°
Dim ShipDate As Double
³o¼Ë§Aªºy­È¤~·|§äªº¨ì
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : ¦a¤WºØ¤Fµæ¡A´N¤£©öªø¯ó¡F¤ß¤¤¦³µ½¡A´N¤£©ö¥Í´c¡C
ªð¦^¦Cªí ¤W¤@¥DÃD