[英]Insert the outcome of a formula using vba
I want to insert a formula in a range of cells in column P. Afterwards I want the outcome of the formula to be a hard value (so not the formula but the outcome).我想在列 P 的一系列单元格中插入一个公式。之后我希望公式的结果是一个硬值(所以不是公式而是结果)。 At the moment I'm placing the formula in the cells, then autofill to last row and then copy column and past special.目前我将公式放在单元格中,然后自动填充到最后一行,然后复制列并过去特殊。 I want to avoid using select - copy - paste.我想避免使用选择 - 复制 - 粘贴。 I was wondering if anyone knows how to do this, I've seen it before but can't find it anymore.我想知道是否有人知道如何做到这一点,我以前见过它,但再也找不到了。
The code I'm using at the moment我目前使用的代码
Set frCP = Worksheets("Compliance").Range("P" & FirstRowFill & ":P" & LastRowMatchC)
With Worksheets("Compliance")
.Range("P" & FirstRow).Offset(1).FormulaArray = "=IF(IFERROR(INDEX(Input!$A$2:A$" & LastRowInput & ",MATCH(1,SEARCH(TRANSPOSE(Input!$A$2:A$" & LastRowInput & "),O" & FirstRowOffset1 & "),0),0),W" & FirstRowOffset1 & ")=0,""ZZ"",IFERROR(INDEX(Input!$A$2:A$" & LastRowInput & ",MATCH(1,SEARCH(TRANSPOSE(Input!$A$2:A$" & LastRowInput & "),O" & FirstRowOffset1 & "),0),0),W" & FirstRowOffset1 & "))"
.Range("P" & FirstRow).Offset(1).AutoFill Destination:=frCP
End With
Columns("P:P").Select
Range("P88").Activate
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
With Worksheets("Compliance")
.Range("A" & FirstRow).Rows(ActiveCell.Row).AutoFilter
.AutoFilter.Sort.SortFields.Clear
.AutoFilter.Sort.SortFields.Add2 Key:= _
.Range("P" & FirstRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
End With
With ActiveWorkbook.Worksheets("Compliance").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
You should be able to replace the whole select-copy-paste block with:您应该能够将整个 select-copy-paste 块替换为:
columns("P:P").value = columns("P:P").value
I'm reading the question correctly, this should also work:我正在正确阅读问题,这也应该有效:
frCP.value = frCP.value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.