[英]Write value of formula into cell with VBA
If i want value from a Excel formula intoa cell and only value not " The formula" 如果我想将Excel公式中的值放入单元格中,而仅不使用“公式”中的值
I have try with this code but it gives me not only the value. 我尝试使用此代码,但它不仅给了我价值。
Dim ZmAntal As Long
Dim CountryRange As Range, C As Range
Dim Res As Variant
ZmAntal = Worksheets("Maskinerum").Cells(8, 4).value
Set CountryRange = Sheets("Zmbistad").Range(Cells(2, 1), Cells(ZmAntal, 1))
For Each C In CountryRange
Res = "=CONCATENATE(RC[1],RC[14])"
If Not IsError(Res) Then
C.Offset(0, 0).value = Res
End If
Next C
End Sub
you could use this: 您可以使用此:
Dim ZmAntal As Long
ZmAntal = Worksheets("Maskinerum").Cells(8, 4).Value
With Sheets("Zmbistad").Range(Cells(2, 1), Cells(ZmAntal, 1)) ' reference relevant range
.FormulaR1C1 = "=CONCATENATE(RC[1],RC[14])" ' write formula in referenced range
.Value = .Value ' get rid of formulas and leave values only in referenced range
.SpecialCells(xlCellTypeConstants, xlErrors).ClearContents ' clear any cell with an "error" value n referenced range
End With
You can use Evaluate
: 您可以使用
Evaluate
:
'...
With CountryRange
.Value = Evaluate("=IF(ROW()," & _
"CONCATENATE(" & .Offset(0, 1).Address & "," & _
"" & .Offset(0, 14).Address & "))")
End With
'...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.