我學緊用VBA, 但好多野唔識,上網睇到有教學就跟住試下 有個位我唔係好知應該點改, 上網搵極都搵唔到類似CASE, 請問有冇人可以幫幫我?

2015-09-18 8:51 am
Sub AddNewItem()

Worksheets("ORDER").Range("$A$1").Select
ActiveCell.End(xlDown).Select

LastRec = ActiveCell.Row + 1

Worksheets("ORDER").Range("B" & LastRec).Value = "=VLOOKUP(Cells(LastRec, 1),PRICELIST!$A$2:$I$1048576,6,0)"

End Sub

結果出黎係#NAME?

回答 (1)

2015-09-19 3:56 am
✔ 最佳答案
Sub test()
Dim Rng As Range
Dim kc As Variant
Set Rng = Sheets("PRICELIST").[A:F]

With Sheets("ORDER")
For i = 2 To .[A65536].End(xlUp).Row
kx = .Cells(i, 1)
kc = Application.VLookup(kx, Rng, 6, 0)
If Not IsError(kc) Then .Cells(i, 2) = kc
Next
End With
End Sub


Sub test()
x = [A65536].End(xlUp).Row
For i = 2 To x
Cells(x, 2).FormulaR1C1 = "=IFERROR(VLOOKUP(RC[-1],PRICELIST!C1:C6,6,0),"""")"
Next
End Sub


收錄日期: 2021-04-18 00:16:53
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20150918005124AA3iaCW

檢視 Wayback Machine 備份