使用VBA将公式的值写入单元格

时间:2018-04-23 07:36:34

标签: excel vba excel-vba

如果我希望将Excel公式中的值放入单元格中,并且仅将值设置为“公式”

我已尝试使用此代码,但它不仅为我提供了价值。

SELECT radnik.*, nalog.prioritetNalog FROM radnik
inner JOIN nalog ON radnik.sifRadnik=nalog.sifRadnik
inner join kvar on nalog.sifKvar=kvar.sifKvar 
WHERE kvar.nazivKvar ="Zamjena klipa";

2 个答案:

答案 0 :(得分:1)

你可以用这个:

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

答案 1 :(得分:0)

您可以使用Evaluate

'...
With CountryRange
    .Value = Evaluate("=IF(ROW()," & _
                            "CONCATENATE(" & .Offset(0, 1).Address & "," & _
                                        "" & .Offset(0, 14).Address & "))")
End With
'...