创建vlookup函数问题并检查条件?

时间:2016-03-18 06:39:18

标签: vba excel-vba excel

我尝试在两张表中创建用于比较日期的vlookup函数,以找出sheet2中可用的给定日期。如果在表2中没有它,则意味着我们可以创建已经可用于该代码的其他明智的告知消息

mycode的

Sub Button1_Click()
Dim ColNum As Integer
Dim Line As String
Dim LineValues() As Variant
Dim OutputFileNum As Integer
Dim PathName As String
Dim RowNum As Integer
Dim SheetValues() As Variant

PathName = Application.ActiveWorkbook.Path
OutputFileNum = FreeFile

Open PathName & "\Upload Additional PDP.csv" For Output Lock Write As #OutputFileNum

Print #OutputFileNum, "Dist_Code" & "," & "Actual_PDP_Date (dd/MM/yyyy)" & "," & "Reason_Code"
Dim rng1 As Range, rng2 As Range, i As Integer, j As Integer

End Sub

代表:

1                   
+--------+--------+---------------+---------+--------+                  
| A      | B      | C             | D       | E      |                  
+--------+--------+---------------+---------+--------+                  
| Code   | Name   | Description   | Price   | Cost   |                  Date
+--------+--------+---------------+---------+--------+                  
| AC33   | Prod 1 | Prod Desc 1   |  3.99   | 2.00   |                  16/7/2014
+--------+--------+---------------+---------+--------+                  
| AC34   | Prod 2 | Prod Desc 2   |  4.99   | 3.00   |                  16/7/2014
+--------+--------+---------------+---------+--------+                  
| AC35   | Prod 3 | Prod Desc 3   |  5.99   | 4.00   |                  16/7/2014
+--------+--------+---------------+---------+--------+                  

2                   

+--------+--------+---------------+---------+                   
| A      | B      | C             | D       |                   
+--------+--------+---------------+---------+                   
| Code   | Name   |Updated Price  | Cost    |               Date    
+--------+--------+---------------+---------+                   
| AC33   | Prod 1 |    16.99      |         |                   
+--------+--------+---------------+---------+                   
| AC37   | Prod 2 |    18.99      |         |                   
+--------+--------+---------------+---------+                   
| AC38   | Prod 3 |    21.99      |         |                   
+--------+--------+---------------+---------+   

1 个答案:

答案 0 :(得分:0)

使用IsError函数测试VLOOKUP的结果,这里有一些东西可以帮助您入门:

If IsError(Application.VLookup(Range("A1"), Range("C:C"), 1, False)) Then
    Debug.Print "Not found"
Else
    Debug.Print "Found"
End If