簡體   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