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