在Excel中匹配时间数据 [英] match the time data in excel
本文介绍了在Excel中匹配时间数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试匹配时间,并且无法通过在Excel中使用VBA获得正确的代码
08:30
09:00
10:00
11:00
12:00
13:00
上方数据位于B1至B6行
Combobox2填充了行"B1:B6"
Combobox2选择以上
之一
我尝试获取由combobox2选择的同一时间的行号
我使用了代码;
I am trying to match the time and unable to get the correct code by using VBA in Excel
08:30
09:00
10:00
11:00
12:00
13:00
Above data’s in rows B1 to B6
Combobox2 is populated with Rows"B1:B6"
Combobox2 selects one of above
I try to get the row number of the same time, selected by combobox2
I used the code;
Dim TheDate As Date
Dim Index As Variant
TheDate = ComboBox2.Value
Index = Application.Match(CLng(TheDate), Range("Sheet1!b1:b10"), 0)
If IsError(Index) Then
MsgBox "Not Found"
Else
MsgBox "Match item: " & Index
End If
有人可以帮我吗?
代码包装在标签代码"中-LOSMAC [/Edited]
Can someone help me please?
Code was wrapped in the tags "code" - LOSMAC[/Edited]
推荐答案
在这种情况下,您无需搜索小时...只需使用ListIndex属性,如下所示:
In this case you don''t need to search hour... Just use ListIndex property, like this:
Private Sub CommandButton1_Click()
MsgBox Me.ComboBox1.ListIndex + 1, vbInformation, "Index of..."
End Sub
这篇关于在Excel中匹配时间数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文