1

Good day I am trying to use VBA to insert the following formula into a Cell:

="last change completed: "& D2&" "&"by " &TEXT(E2;"dd-mmm-yy")

Where D2 would be a name and E2 would be a date. If i use the macro record i get:

Sub Macro8()
'
' Macro8 Macro
'

'
    Range("D12").Select
   ActiveCell.FormulaR1C1 = _
    "=""last change completed: ""& R[-11]C[-1]&"" ""&""on "" &TEXT(R[-11]C,""dd-mmm-yy"")"
   ' ActiveCell.FormulaR1C1 = _
        "=""last change completed: ""& R2C4&"" ""&""on "" &TEXT(R2C5,""dd-mmm-yy"")"
    Range("D13").Select
End Sub

The problem i have is the moment i try to change the cell locations to variables i get broken formulas in the cell, for example something similar to :

="last change completed: "  &@ Range(SOP1)

where the "@range(SOP1) was supposed to be a variable cell location. i hope this is enough detail.

4

1 回答 1

1

请看下面的代码。希望这可以解决您的问题。

根据需要更改 sheet(1) 值(1- 指工作簿中的第一张工作表)

Sub Macro8()

rng1 = "D12"
rng2 = "D1"

ThisWorkbook.Sheets(1).Range("A1").Formula = "=""last knifehead change: """ & " & " & rng1 & " " & " & " & """ on """ & " & " & "Text(" & rng2 & ", ""dd-mmm-yy"")"

End Sub
于 2020-06-05T18:32:46.410 回答