首页 > 解决方案 > 类型不匹配问题 VBA - 公式到值

问题描述

我有一个范围,首先我用公式填充然后我试图将它转换为一个值,然后我使用 sumifs 基于标准的范围。但是,我得到

类型不匹配错误

在我使用 Sumifs 的那一行。我想我的错误来自将值从公式更改为值。但是,我不能使用 Select、Copy、PasteSpecial,因为我有超过 2084 行。我已经挣扎了很长一段时间。有什么建议么?

Dim DWR, MHR, P, D As Worksheet

Set DWR = Sheets("DWREP")
Set MHR = Sheets("MACH-HRS")
Set P = Sheets("PRODUCTION")
Set D = Sheets("DELAYS")
Dim planned_time, tech_time, lost_time, std_time As Long

Dim last_row, last_row1, last_row2 As Long
last_row = MHR.Cells(Rows.Count, 1).End(xlUp).Row
last_row1 = P.Cells(Rows.Count, 1).End(xlUp).Row
last_row2 = D.Cells(Rows.Count, 1).End(xlUp).Row
    If P.range("CC2").Formula = "" Then
    P.range("CC2").FormulaR1C1 = "=PRODUCTION!RC[-66]/VLOOKUP(PRODUCTION!RC[-76],STD!R3C1:R1030C17,17,FALSE)"

P.range("CC2").AutoFill Destination:=P.range("CC2:CC" & last_row1), Type:=4
P.range("CC2:CC" & last_row1).Font.Color = RGB(255, 255, 255)
With P
    With .range("CC2" & last_row1)
        .Value = .Value
    End With
End With
End If
std_time = Application.SumIfs(P.range("CC2:CC" & last_row1), P.range("A2:A" & last_row1), DWR.Cells(7, i), P.range("C2:C" & last_row1), DWR.range("B31"))

标签: excelvbasumifs

解决方案


你错过了你的With街区的专栏。

改变: .range("CC2" & last_row1)

为了: .range("CC2:CC" & last_row1)


推荐阅读