繁体   English   中英

运行时错误 13' 类型不匹配 VBA excel

[英]Runtime error 13' Type missmatch VBA excel

这是尝试根据条件修改某些单元格背景颜色的代码。 它在我创建代码的朋友的计算机上工作,但是当我将它发送到我的计算机并运行它时,出现消息类型不匹配。

调试器在分配 Cells(i,j).Interior.Color = RGB(0,255,0) 处停止

也许它与 excel 版本兼容???

Sub Acumuladores()

Dim j As Integer
Dim i As Integer
Dim Title As String
Dim numColumnas As Integer

numColumnas = 36

j = 1
Do While j < numColumnas
    Title = Cells(1, j)
    i = 1
    Do While Cells(i, 1) <> ""
        i = i + 1
        If (i Mod 2 = 0) Then
            If (Title = "PV" Or Title = "PPALUNITCCY1" Or Title = "PPALUNITCCY1" Or Title = "IMPORTE_TOTAL_ACUMULADO" Or Title = "FXFORWARDPPAL" Or Title = "FXFORWARDRATE" Or Title = "FXFWDVTO") Then
               If Cells(i, j) = -Cells(i + 1, j) Then
                    Cells(i, j).Interior.Color = RGB(0, 255, 0)
                Else
                    Cells(i, j).Interior.Color = RGB(255, 0, 0)
                End If
            End If
            If (Title = "TIPOEMISION" Or Title = "STARTDATE" Or Title = "MATURITYDATE" Or Title = "DESCRIPTION" Or Title = "CECACUMTIPO" Or Title = "CECACUMRATIO" Or Title = "CECACUMRATIO1" Or Title = "CECACUMNOBS" Or Title = "CECACUMFREQ" Or Title = "CECACUMSTRIKE" Or Title = "CECACUMBARRERA") Then
                If Cells(i, j) = Cells(i + 1, j) Then
                    Cells(i, j).Interior.Color = RGB(0, 255, 0)
                Else
                    Cells(i, j).Interior.Color = RGB(255, 0, 0)
                End If
            End If
        End If
    Loop
    j = j + 1
Loop

End Sub

在 if 语句中:

If Cells(i, j) = -Cells(i + 1, j) Then
  Cells(i, j).Interior.Color = RGB(0, 255, 0)
Else

你有-Cells而不是Cells 所以使用以下方法修复它:

If Cells(i, j) = Cells(i + 1, j).Value * -1Then
  Cells(i, j).Interior.Color = RGB(0, 255, 0)
Else

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM