Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2222|回复: 2

[已解决]关于typename函数的问题

[复制链接]
发表于 2013-12-20 16:39 | 显示全部楼层 |阅读模式
详见附件
最佳答案
2013-12-21 07:57
  1. Sub c()
  2. Dim c As Range, b As String
  3. For Each c In [A1:E6]
  4. b = TypeName(c.Value)
  5.     If b = "Double" Then
  6.         c.Font.ColorIndex = 3
  7.     End If
  8. Next
  9. End Sub
复制代码
上面的代码只是把所有的数值(含小数)标注为红色;
如果仅仅将整数标注为红色,可以用下面的代码:
  1. Sub JustInteger()
  2. Dim c As Range, b As String
  3. For Each c In [A1:E6]
  4. b = TypeName(c.Value)
  5.     If b = "Double" Then
  6.         If Int(c.Value) = c.Value Then c.Font.ColorIndex = 3
  7.     End If
  8. Next
  9. End Sub
复制代码
第二段代码只能将数值型整数标注为红色,如果要把所有的整数(包含数值型整数和文本型整数)标注为红色,请用下面的代码:
  1. Sub JustInteger02()
  2. Dim c As Range
  3. On Error GoTo 100
  4. For Each c In [A1:E6]
  5.     If Int(Val(c.Value)) = c.Value Then c.Font.ColorIndex = 3
  6. 100
  7. Next
  8. End Sub
复制代码

typename函数.rar

6.73 KB, 下载次数: 17

excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2013-12-20 18:00 | 显示全部楼层
Sub c()
Dim c As Range, b As String
For Each c In [A1:E6]
    If IsNumeric(c.Value) Then
        If c.Value - c.Value = 0 Then
            c.Font.ColorIndex = 3
        End If
    End If
Next
End Sub
这样试试
回复

使用道具 举报

发表于 2013-12-21 07:57 | 显示全部楼层    本楼为最佳答案   
  1. Sub c()
  2. Dim c As Range, b As String
  3. For Each c In [A1:E6]
  4. b = TypeName(c.Value)
  5.     If b = "Double" Then
  6.         c.Font.ColorIndex = 3
  7.     End If
  8. Next
  9. End Sub
复制代码
上面的代码只是把所有的数值(含小数)标注为红色;
如果仅仅将整数标注为红色,可以用下面的代码:
  1. Sub JustInteger()
  2. Dim c As Range, b As String
  3. For Each c In [A1:E6]
  4. b = TypeName(c.Value)
  5.     If b = "Double" Then
  6.         If Int(c.Value) = c.Value Then c.Font.ColorIndex = 3
  7.     End If
  8. Next
  9. End Sub
复制代码
第二段代码只能将数值型整数标注为红色,如果要把所有的整数(包含数值型整数和文本型整数)标注为红色,请用下面的代码:
  1. Sub JustInteger02()
  2. Dim c As Range
  3. On Error GoTo 100
  4. For Each c In [A1:E6]
  5.     If Int(Val(c.Value)) = c.Value Then c.Font.ColorIndex = 3
  6. 100
  7. Next
  8. End Sub
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-6 06:30 , Processed in 0.278626 second(s), 10 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表