带 Excel 数据库的 VBA 计数器
我正在为 Excel 工作表编写一些宏,将点添加到数据库中。这些条目的纬度和经度值必须是唯一的,因此我添加了几行代码,用于在用户尝试输入条目后检查条目的纬度/经度。它的目的是根据数据库中的所有条目检查待处理条目的纬度/经度。如果匹配,就会返回错误。代码如下:
x = 2
Do Until (Worksheets("DBase").Cells(x, 3).Value = "")
If Worksheets("DBase").Cells(x, 3).Value = lat And Worksheets("DBase").Cells(x,
4).Value = lon Then
GoTo coorAbort
Else
x = x + 1
End If
Loop
x 是行计数器,lat 和 lon 是用户输入的纬度/经度,coorAbort 是包含错误消息的部分。一切工作正常,除了将循环推进到下一行的计数器似乎不起作用。它检查第二行条目,然后退出循环并继续执行代码的下一部分。我确信我有一些小事情搞砸了,但我似乎无法把它找出来。有人有什么想法吗?
I'm writing some macros for an excel worksheet that will add points to a database. The entries need to be unique with respect to their latitude and longitude values, so I've added a a few lines of code that will check the lat/long of an entry after a user has tried to enter it. It is intended to check the lat/long of a pending entry against all the ones in the database. If it matches one, it will return an error. Here is the code:
x = 2
Do Until (Worksheets("DBase").Cells(x, 3).Value = "")
If Worksheets("DBase").Cells(x, 3).Value = lat And Worksheets("DBase").Cells(x,
4).Value = lon Then
GoTo coorAbort
Else
x = x + 1
End If
Loop
x is the row counter, lat and lon are the lat/long's inputted by the user, and coorAbort is the section with the error message. Everything works fine except the counter to progress the loop to the next row doesn't seem to be working. It checks the second row entry and then exits the loop and moves on to the next part of the code. I'm sure I have something small messed up, I just can't seem to pick it out. Anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜
lat
和lon
是双精度值?如果是这样,您应该替换为
(并且对于
lon
执行相同的操作)。切勿直接测试 double 值是否相等。I guess
lat
andlon
are double values? If so, you should replaceby
(and for
lon
do the same). Never test double values directly for equality.