2017-02-17 37 views
0

我有一个用户窗体有两个文本框命名为“日期”和“移位”,按钮来触发代码。还有一个名为data.xlsx的excel文件,“sheet1”的A列的日期已添加为07/02/2017,B列的添加为A/B/C。用VBA找到多个条件

date.value = "07/02/2017" 
shift.value = "C" 

,所以我想要做的是找到一个列的行数中包含“2017年7月2日”和B列中包含“C”的data.xlsx。

+0

什么样的方法你试过这么远吗?提供正在进行的工作。 – Zerk

+0

使用MATCH()函数怎么样? –

回答

0

请尝试下面的代码以找到列B中的Shift行(使用Match函数)。

您应该可以进行修改以使其也可以从dateTextBox中查找日期。

代码

Sub CommandButton1_Click() 

' this code goes inside the command button (inside the User_Form module) 
Dim ValToSearch 
Dim MatchRes As Variant 

ValToSearch = Me.shift.Value '<-- get the value to look for 

With Worksheets("Sheet1") 
    MatchRes = Application.Match(ValToSearch, .Range("B:B"), 0) 
    If IsError(MatchRes) Then '<-- match not found 
     MsgBox "Not found" 
    Else 
     MsgBox "Found at row " & MatchRes 
    End If 
End With 

End Sub 
+0

感谢您的回答。但是我看到你只在B列中找到shift.value。 A列中的date.value怎么样?我需要同时找到两个。 –

+0

@MahmutUzun我有你这个概念,肯定你可以尽最大努力去适应另一种情况 –

+0

我已经通过使用“if”和chechking其他列来了这么远。但它会带来另一个问题。谢谢你的回答。 –