vba将公式转换为值

我已经写了一个子使用自动填充设置一个单元格在特定范围countifs公式,但我似乎无法得到它将范围从公式转换为值之后。

我想避免使用复制,粘贴特殊来做到这一点。 我试图使用.value = .value的一些不同的变体,但似乎没有能够得到这个工作正常,通常它只是将所有的值设置为1,我知道是不正确的,任何帮助将不胜感激

我附上了一个下面的工作代码的副本,将单元格设置为countifs公式,以避免与我所做的.value = .value错误混淆

谢谢

' wsWorksheet is the worksheet to be used ' lngFirstRow is the first row of data ' strSourceCol is the letter (eg A) of the column to be counted ' strCountCol is the letter (eg I) of the column to add the count result to Sub Concurrency(wsWorksheet As Worksheet, lngFirstRow As Long, strSourceCol As String, strCountCol As String) Dim lngLastRow As Long Dim strFormula As String Const ConcFormula As String = "=(COUNTIFS(D$1:D1,"">""&C2,A$1:A1,A2))+1" 'Find the last row of data in the source column With wsWorksheet lngLastRow = .Cells(.Rows.Count, strSourceCol).End(xlUp).Row If lngLastRow < lngFirstRow Then lngLastRow = lngFirstRow End With 'With the first cell on the count column With wsWorksheet.Cells(lngFirstRow, strCountCol) 'Add the count formula .Formula = ConcFormula 'If there are more rows autofill it down If lngLastRow > lngFirstRow Then .AutoFill Destination:=Range( _ .Cells, _ .Offset(rowoffset:=lngLastRow - lngFirstRow).Cells), Type:=xlFillDefault End If End With End Sub 

你应该能够做到这一点:

 With wsWorksheet With .Range(.Cells(lngFirstRow, strCountCol), .Cells(lngLastRow, strCountCol)) 'Add the count formula .Formula = ConcFormula .Value2 = .Value2 End With End With