VBA-更改具有多个单元格值的其他单元格

时间:2018-10-27 03:22:35

标签: excel vba excel-vba

在excel中使用VBA,我想为所有以B9开始的值的B行并入位于“ O”列中的公式,如下所示。请参考图片。

=“”&D9&“”&I9&“(MK号“&B9&”)”

enter image description here

3 个答案:

答案 0 :(得分:0)

这应该可以满足您的需求。

Sub Pasteformula()

Dim LookupRange As Range
Dim c As Variant

Application.ScreenUpdating = False
Set LookupRange = Range("B9:B500") ' Set range in Column B

For Each c In LookupRange 'Loop through range
    If c.Value <> "" Then 'If value in B is empty then
        Cells(c.Row, 15).FormulaR1C1 = _
            "=""""&RC[-11]&"" ""&RC[-6]&"" (MK NO. ""&RC[-13]&"")""" 'Apply formula
    End If
Next c
Application.ScreenUpdating = True
End Sub

答案 1 :(得分:0)

设置范围并输入公式,然后将范围更改为值。

Sub Button1_Click()
    Dim rng As Range
    Set rng = Range("O9:O" & Cells(Rows.Count, "B").End(xlUp).Row)
    rng.Formula = "=CONCATENATE(D9,"" "",I9,"" (MK NO. "",B9,"")"")"
    rng.Value = rng.Value
End Sub

答案 2 :(得分:0)

从您的叙述中我发现您已经在O9中拥有适当的公式,因此您可以使用Range对象的Range("O9").AutoFill Range("B9", Cells(Rows.Count, "B").End(xlUp)).Offset(,13) 方法:

sorted(L, key=lambda x: str(x)[::-1])