ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 676|回复: 2

[求助] 类型不匹配,如何解决?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2017-5-14 12:57 | 显示全部楼层 |阅读模式
Sub 凌空一羽()
Application.ScreenUpdating = False
For i = 3 To 65536
    '标题------------
    If i Mod 4 = 3 Then
        Range("bc" & i - 1 & ":be" & i - 1).Copy Cells(i - 1, "Aq")
        Range("bh" & i - 1 & ":bj" & i - 1).Copy Cells(i - 1, "At")
    End If
    '------------标题
   '内容------------
    If (i - 3) Mod 4 < 2 Then   '取前2个
        gi = Int((i + 1) / 4) * 4 - 1
        '执行只取唯一最小(大)值------------
        If Application.CountIf(Cells(gi, "aw").Resize(1, 3), "<1") = 1 Then
            gmin = Application.Min(Cells(gi, "aw").Resize(1, 3))
            gmc = Application.Match(gmin, Cells(gi, "aw").Resize(1, 3), 0)
        Else
            gmax = Application.Max(Cells(gi, "aw").Resize(1, 3))
            gmc = Application.Match(gmax, Cells(gi, "aw").Resize(1, 3), 0)
        End If
        '------------执行只取唯一最小(大)值
        For j = 1 To 6
            If j > 3 Then  '分2个区域选择值
                gb = Cells(i, "BG").Offset(0, gmc)
                If Cells(i, j + 56) = gb Then
                    Cells(i, j + 42) = "等于参照": Cells(i, j + 42).Interior.ColorIndex = 5: Cells(i, j + 42).Font.ColorIndex = 2: Cells(i, j + 42).Font.Bold = True  '颜色变化
                ElseIf Cells(i, j + 56) > gb Then
                    Cells(i, j + 42) = "大于参照": Cells(i, j + 42).Interior.ColorIndex = 3: Cells(i, j + 42).Font.ColorIndex = 6: Cells(i, j + 42).Font.Bold = True
                Else
                    Cells(i, j + 42) = "小于参照": Cells(i, j + 42).Interior.ColorIndex = 7: Cells(i, j + 42).Font.ColorIndex = 6: Cells(i, j + 42).Font.Bold = True
                End If
                If j - 3 = gmc Then Cells(i, j + 42) = "参照": Cells(i, j + 42).Interior.ColorIndex = 40: Cells(i, j + 42).Font.ColorIndex = 1: Cells(i, j + 42).Font.Bold = True
            Else
                ga = Cells(i, "BB").Offset(0, gmc)
                If Cells(i, j + 54) = ga Then
                    Cells(i, j + 42) = "等于参照": Cells(i, j + 42).Interior.ColorIndex = 5: Cells(i, j + 42).Font.ColorIndex = 2: Cells(i, j + 42).Font.Bold = True
                ElseIf Cells(i, j + 54) > ga Then
                    Cells(i, j + 42) = "大于参照": Cells(i, j + 42).Interior.ColorIndex = 3: Cells(i, j + 42).Font.ColorIndex = 6: Cells(i, j + 42).Font.Bold = True
                Else
                    Cells(i, j + 42) = "小于参照": Cells(i, j + 42).Interior.ColorIndex = 7: Cells(i, j + 42).Font.ColorIndex = 6: Cells(i, j + 42).Font.Bold = True
                End If
                If j = gmc Then Cells(i, j + 42) = "参照": Cells(i, j + 42).Interior.ColorIndex = 40: Cells(i, j + 42).Font.ColorIndex = 1: Cells(i, j + 42).Font.Bold = True
            End If
        Next
    End If
    '------------ 内容
Next
Application.ScreenUpdating = True
End Sub
122442z0i7aqg2r5vqp1zz.png
附件
按条件比较数值大小(修改).rar (13.73 KB, 下载次数: 2)

TA的精华主题

TA的得分主题

发表于 2017-5-14 13:43 | 显示全部楼层
  1. Sub 比较大小()
  2. Application.ScreenUpdating = False
  3. For i = 3 To Range("bc10000").End(3).Row
  4.     '标题------------
  5.     If i Mod 4 = 3 Then
  6.         Range("bc" & i - 1 & ":be" & i - 1).Copy Cells(i - 1, "Aq")
  7.         Range("bh" & i - 1 & ":bj" & i - 1).Copy Cells(i - 1, "At")
  8.     End If
  9.     '------------标题
  10.    '内容------------
  11.     If (i - 3) Mod 4 < 2 Then   '取前2个
  12.         gi = Int((i + 1) / 4) * 4 - 1
  13.         '执行只取唯一最小(大)值------------
  14.         If Application.CountIf(Cells(gi, "aw").Resize(1, 3), "<1") = 1 Then
  15.             gmin = Application.Min(Cells(gi, "aw").Resize(1, 3))
  16.             gmc = Application.Match(gmin, Cells(gi, "aw").Resize(1, 3), 0)
  17.         Else
  18.             gmax = Application.Max(Cells(gi, "aw").Resize(1, 3))
  19.             gmc = Application.Match(gmax, Cells(gi, "aw").Resize(1, 3), 0)
  20.         End If
  21.         '------------执行只取唯一最小(大)值
  22.         For j = 1 To 6
  23.         Cells(i, j + 42).Font.Bold = True
  24.             If j > 3 Then  '分2个区域选择值
  25.                 gb = Cells(i, "BG").Offset(0, gmc)
  26.                 If Cells(i, j + 56) = gb Then
  27.                     Cells(i, j + 42) = "等于参照": Cells(i, j + 42).Interior.ColorIndex = 5: Cells(i, j + 42).Font.ColorIndex = 2   '颜色变化
  28.                 ElseIf Cells(i, j + 56) > gb Then
  29.                     Cells(i, j + 42) = "大于参照": Cells(i, j + 42).Interior.ColorIndex = 3: Cells(i, j + 42).Font.ColorIndex = 6
  30.                 Else
  31.                     Cells(i, j + 42) = "小于参照": Cells(i, j + 42).Interior.ColorIndex = 7: Cells(i, j + 42).Font.ColorIndex = 6
  32.                 End If
  33.                 If j - 3 = gmc Then Cells(i, j + 42) = "参照": Cells(i, j + 42).Interior.ColorIndex = 40: Cells(i, j + 42).Font.ColorIndex = 1
  34.             Else
  35.                 ga = Cells(i, "BB").Offset(0, gmc)
  36.                 If Cells(i, j + 54) = ga Then
  37.                     Cells(i, j + 42) = "等于参照": Cells(i, j + 42).Interior.ColorIndex = 5: Cells(i, j + 42).Font.ColorIndex = 2
  38.                 ElseIf Cells(i, j + 54) > ga Then
  39.                     Cells(i, j + 42) = "大于参照": Cells(i, j + 42).Interior.ColorIndex = 3: Cells(i, j + 42).Font.ColorIndex = 6
  40.                 Else
  41.                     Cells(i, j + 42) = "小于参照": Cells(i, j + 42).Interior.ColorIndex = 7: Cells(i, j + 42).Font.ColorIndex = 6:
  42.                 End If
  43.                 If j = gmc Then Cells(i, j + 42) = "参照": Cells(i, j + 42).Interior.ColorIndex = 40: Cells(i, j + 42).Font.ColorIndex = 1
  44.             End If
  45.         Next
  46.     End If
  47.     '------------ 内容
  48. Next
  49. Application.ScreenUpdating = True
  50. End Sub
复制代码

(0g4ldai84.zip

16.32 KB, 下载次数: 2

TA的精华主题

TA的得分主题

 楼主| 发表于 2017-5-14 17:08 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-6-11 08:40 , Processed in 0.034432 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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