嗨,感谢您的帮助。使用.find的问题
我制作了一个小型宏,它将原始格式的大学课程转换为一些描述的时间表...它使用.find找到了一天,然后使用.find开始和结束时间,然后将数据绘制到适当的单元格中。一切都很好,直到遇到5个字符长的时间,例如15.15; 12.25 14.35。它对一切都很满意。我想这可能是我如何声明变量的问题,或者是.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
你可以试试'9.15'的时间,看看是否也会产生错误?我认为你几乎肯定有浮点精度问题 – barrowc
嘿,谢谢你的回应!不幸的是,我只是试了一下,9.15也产生了错误。这是否意味着它不是浮点舍入错误? stoptime变量被定义为Single;那不处理浮点? –
尝试格式化您的单元格为'时间' – jsotola