【问题标题】:Insert HLOOKUP formula if cell contains text如果单元格包含文本,则插入 HLOOKUP 公式
【发布时间】:2018-06-11 07:21:49
【问题描述】:

这是我的电子表格的样子:

enter image description here

如果单元格包含 58DV,我想在 58DV 右侧的单元格中插入 HLOOKUP 公式。如果没有数据,则无需执行任何操作。我对 VBA 还是很陌生,所以我不确定如何在 VBA 中使用公式。谢谢

Sub sitelookup()

With Application
    .ScreenUpdating = False
End With

Dim SrchRng As Range, cel As Range

Set SrchRng = Range("C4:C1299")

For Each cel In SrchRng
    If cel > 0 Then
        cel.Offset(0,1).value = Application.WorksheetFunction.HLOOKUP(F4,'Raw G'!2:5,2,0)

    End If
Next cel

End Sub

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    试试,

    with worksheets("sheet1")
        Set SrchRng = .Range(.cells(4, "B"), .cells(rows.count, "B").end(xlup))
    
        For Each cel In SrchRng
            If cel.value2 = "58DV" Then
               'to put the formula's value into the neighboring cell
                cel.Offset(0, 1).value = _
                   Application.HLOOKUP(.cells(cel.row, "F"), worksheets("Raw G").range("2:5"), 2, 0)
               'to put the formula into the neighboring cell
                'cel.Offset(0, 1).formula = _
                   "=HLOOKUP(F" & cel.row & ",'Raw G'!2:5, 2, 0)"
            End If
        Next cel
    end with
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-08
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多