如何插入基于单元格的值

如何告诉VBAselectA9中的任何一个,使用A9中的值(即B5),然后转到B5并插入值22(B9中的值)。

在这里输入图像说明

输出应该是这样的:

在这里输入图像说明

在B5中插入22值。 有没有办法,我可以用Excel公式或VBA编程语言来做到这一点。

你可能想要做这样的事情:

Sub asd() Dim dd = [A9].Value Range(d) = [A9].Offset(0, 1) End Sub 
 Sub DoIt1() Range(Range("A9")).Value = Range("B9").Value End Sub 

试试这个模块:

 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 

回应评论中的问题(检查单元格内容是否在第一个范围内):

 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 

要引用A9中的值,您可以使用

 Range("A9").select 

要引用相邻B列中的值,可以使用偏移function。

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

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

您可以使用:

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