使用.find的问题

嗨,感谢您的帮助提前。

我制作了一个小的macros,它把我的大学课程从一个原始格式转换成一个描述的时间表…find一天使用.find,然后使用.find开始和结束时间,然后绘制数据放入适当的单元格中。 一切都很好,直到遇到5个字符的时间,例如15.15; 12.25 14.35。 它与其他一切都很满意。 我想这可能是我如何声明variables的一个问题,或与.find和经过广泛的故障排除后,我没有更接近的工作了。 根据5个字符时间是否在课程的开始或结束时间,问题在起始停止行或起始行中出现。 这是违规的代码:

Sub MakeSchedule() Dim x As Long Dim y As Long Dim tot As Long Dim xday As Long Dim xdetails As Long Dim xstart As Long Dim xstoptime As Long Dim day As String Dim details As String Dim start As Single Dim stoptime As Single Dim daycol As Long Dim startrow As Long Dim stoptimerow As Long xday = 3 xstart = 4 xstoptime = 5 xdetails = 6 Range("I1").Select tot = ActiveCell.End(xlDown).Row - 1 For y = 1 To tot day = ActiveCell.Offset(y, xday).Value daycol = Range("B1:F1").Find(day, LookIn:=xlValues, lookat:=xlWhole).Column start = ActiveCell.Offset(y, xstart).Value stoptime = ActiveCell.Offset(y, xstoptime).Value details = ActiveCell.Offset(y, xdetails).Value startrow = Range("A1:A134").Find(start, LookIn:=xlValues, lookat:=xlWhole).Row stoptimerow = Range("A1:A134").Find(stoptime, LookIn:=xlValues, lookat:=xlWhole).Row Range(Cells(startrow, daycol), Cells(stoptimerow, daycol)).Value = details Next End Sub 

不要在查找中使用单一数据types。 更好地使用Variant数据types。

 Sub FIND_Converts_Single_To_Double() Dim sSingle As Single, dDouble As Double, a As Double 'Dim sSingle As Variant, dDouble As Double, a As Double a = 22.23 sSingle = a dDouble = a Debug.Print sSingle = dDouble Debug.Print dDouble, sSingle, CDbl(sSingle) cells(1,1).value=a Set c1 = Range("A1:A134").Find(sSingle, , LookIn:=xlValues, lookat:=xlWhole) Set c2 = Range("A1:A134").Find(dDouble, , LookIn:=xlValues, lookat:=xlWhole) If c1 Is Nothing Then Debug.Print "Nothing" Else Debug.Print c1 End If Debug.Print c2 End Sub