如何根据单元格插入值

时间:2015-02-26 13:52:32

标签: excel vba excel-vba excel-formula

如何告诉VBA选择A9中的任何内容,使用A9中的值(即B5),然后转到B5并插入值22(在B9中)。

enter image description here

输出应该如下所示:

enter image description here

在B5中插入了22个值。有没有办法使用excel公式或VBA编程语言来做到这一点。

5 个答案:

答案 0 :(得分:1)

Sub DoIt1()
    Range(Range("A9")).Value = Range("B9").Value

End Sub

答案 1 :(得分:1)

您可能想要这样做:

Sub asd()

    Dim d 

    d = [A9].Value

    Range(d) = [A9].Offset(0, 1)

End Sub

答案 2 :(得分:1)

试试这个模块:

sub copy_paste_fun()

    dim new_range as string
    new_range = range("A9").value

    dim new_value as double
    new_value = range("B9").value

    range(new_range) = new_value
end sub

答案 3 :(得分:0)

要参考A9中的值,您可以使用

Range("A9").select

要参考相邻B列中的值,您可以使用偏移功能。

Range("A9").Offset(0, 1).Select

但我觉得也不需要使用偏移功能:

您可以使用:

Range(Range("A9")).Value = Range("B9").Value

答案 4 :(得分:0)

回答评论中的问题(检查单元格的内容是否首先包含范围):

Sub DoDoDo()
    Dim rng As Range

    On Error Resume Next
        Set rng = Range(Range("A9").Value)
    On Error GoTo 0

    If Not rng Is Nothing Then
        rng.Value = 99
    Else
        'Do Nothing or Catch the error
    End If
End Sub
相关问题