我是使用vba的新手,我不知道如何询问以下内容。
我有我的数据库,它看起来像这样:
Category Description Category1 Description1
a 1 c ____
b 2 b ____
c 3 a ____
... ... ... ...
我必须根据类别复制description1中的描述。
注意:类别和描述具有相同的长度,但category1和description1具有另一个长度。
我目前使用以下代码:
Private Sub clasi_Click()
Dim i As Integer
Dim final1, final2 As Integer
Dim description As String
Dim categoria As Single
Worksheets("Sheet3").Select
final1 = Application.CountA(Worksheets("Sheet1").Range("d:d")) '99 cells
final2 = Application.CountA(Worksheets("Sheet1").Range("a:a")) '656 cells
For i = 1 To final2
description = Worksheets("Sheet3").Cells(i, 3).Value
Worksheets("Sheet3").Cells(i, 8).Value =
Application.WorksheetFunction.VLookup(description, Range("a:b"), 2, 1)
Next i
End Sub
出现:运行时错误' 1004'无法获取WorksheetFunction类的Vlookup属性。
我不知道是什么问题,谢谢你的帮助。
答案 0 :(得分:0)
下一个代码效果很好!
Private Sub clasificar_Click()
Dim i As Integer
Dim final1, final2 As Integer
Dim description As String
Dim categoria As Single
Worksheets("Sheet1").Select
final1 = Application.CountA(Worksheets("Sheet1").Range("d:d")) '99 cells
final2 = Application.CountA(Worksheets("Sheet1").Range("a:a")) '656 cells
For i = 1 To final2
On Error Resume Next
description = Worksheets("Sheet1").Cells(i, 5).Value
Worksheets("Sheet1").Cells(i, 9).Value =
Application.WorksheetFunction.VLookup(description, Range("a:b"), 2, 0)
If Err.Number = 1004 Then Worksheets("Sheet1").Cells(i, 9).Value = "Sin
categoria"
Next i
End Sub