VBA整型变量问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 04:03:20
我在EXCEL宏VB editor里写了一个比较单元格里数值大小的程序,然后大的涂上颜色,但是有的就判断不了大小,例如两个单元格显示55%、55%,按理说应该相等,但在程序里执行一个是0.552223656 另一个是0.546885524,单元格里把它四舍五入了,而在程序里没有,怎么能让程序不精确到这么小。谢谢高手回答。
dim i as integer,j as integer,s,n as integer
for i=1 to 4'行
s=0
for j=1 to 4'列
if cells(i,j)>s then s=cells(i,j):n=j
next j
Cells(i, n).Interior.Color = RGB(255, 255, 0)
next i
高手你还在吗 你有QQ吗 能和你聊一下吗?

不用那么麻烦~如果你只是想比较单元格显示的内容的大小的话只要用cells(i,j).text来代替cells(i,j).value就可以了~cells的默认属性是value,所以cells(i,j)表示的是cells(i,j).value~所以你的代码可以改成:

dim i as integer,j as integer,s,n as integer
for i=1 to 4'行
s=0
for j=1 to 4'列
if cells(i,j).text>s then s=cells(i,j).text:n=j
next j
Cells(i, n).Interior.Color = RGB(255, 255, 0)
next i
问题补充:高手你还在吗 你有QQ吗 能和你聊一下吗?

把判断那行"if..."的前半部分,里边改成:
if int(100*cells(ij))>int(100*s)
后半行一样,我手里没装环境,如果不对请在问题补充里告诉我。

dim i as integer,j as integer,s,n as integer
for i=1 to 4'行
s=0
for j=1 to 4'列
if round(cells(i,j),2)>s then s=round(cells(i,j),2):n=j
next j
Cells(i, n).Interior.Color = RGB(255, 255, 0)
next i

子易空间站 - Excel培训专家

不好意思,昨天晚上有事没来得及给你写,刚写了一下,测试过没有问题,你看一下:

'代码开始================================
Sub Temp()

Dim iRow, iColumn, iMax, iiMaxColumn, m, n, i, j As In