返回列表 上一主題 發帖

"Vlookup" and "Match" in VBA

本帖最後由 Hsieh 於 2011-6-25 18:51 編輯

回復 19# am0251
x = Application.Match(ItemName, Sheet2.["A1", "A" & myRowCount], 0)
這是錯誤語法,改為
x = Application.Match(ItemName, Sheet2.Rnage("A1:A" & myRowCount), 0)

日期在工作表內被視為Double資料型態
所以應宣告為
Dim ShipDate As Double
這樣你的y值才會找的到
學海無涯_不恥下問

TOP

本帖最後由 Hsieh 於 2011-6-26 22:54 編輯

回復 21# am0251
既然已經宣告成DOUBLE型態
ShipDate = Format(Calendar1.Value, "d-mmm-yy")
這樣又轉成了字串,當然型態不符
直接ShipDate =Calendar1.Value
只針對語法解釋,其他不了解你的目的是甚麼?無法給你任何意見
學海無涯_不恥下問

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] '工作表名稱
  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
複製代碼
學海無涯_不恥下問

TOP

.Cells(a.Row, k) = .Cells(a.Row, k) +d(a.Value)
學海無涯_不恥下問

TOP

        靜思自在 : 真正的愛心,是照顧好自己的這顆心。
返回列表 上一主題