Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 创建具有不同查找范围的按钮_Vba_Excel - Fatal编程技术网

Vba 创建具有不同查找范围的按钮

Vba 创建具有不同查找范围的按钮,vba,excel,Vba,Excel,使用此选项创建按钮:- Sub CreateButton4() Dim i& With ActiveSheet i = .Shapes.Count With .Buttons.Add(199.5, 20 + 46 * i, 81, 36) .Name = "New Button" & Format(i, "00") .OnAction = "MoveValue" .Characters.Text = "Submit

使用此选项创建按钮:-

Sub CreateButton4()
Dim i&
With ActiveSheet
    i = .Shapes.Count
    With .Buttons.Add(199.5, 20 + 46 * i, 81, 36)
        .Name = "New Button" & Format(i, "00")
        .OnAction = "MoveValue"
        .Characters.Text = "Submit " & Format(i, "00")
    End With
End With
运行MoveValue子对象的:-

Sub MoveValue()
With Sheets("Sheet1").Columns(8).Find(Range("C3").Value, , , 1).Offset(0, 1)
    .Value = .Value + Sheets("Sheet1").Range("D3").Value
End With
问题是我希望MoveValue与它相邻的单元格相关,因为我有另一个sub,当按钮创建时,它会将数据提交到相邻的单元格,而我只编写了第一个按钮。我不确定我是不是走错了路。任何帮助都将不胜感激


您可以使用TopLeftCell属性,如图所示。但是,您必须像这样更改布局,以便按钮的左上角单元格与所需信息位于同一行中

    Sub CreateButton4()
      Dim i&
      With ActiveSheet
        i = .Shapes.Count
          With .Buttons.Add(199.5, 35 + 46 * i, 81, 36)
            .Name = "New Button" & Format(i, "00")
            .OnAction = "MoveValue"
            .Characters.Text = "Submit " & Format(i, "00")
         End With
      End With
  End Sub



  Sub MoveValue()

        Dim tlcRow As Integer

        tlcRow = ActiveSheet.Shapes(Application.Caller).TopLeftCell.row

        With Plan1
            .Range("H3:H8").Find(.Range("C" & tlcRow).Value).Offset(0, 1).Value = .Range("D" & tlcRow).Value
        End With

    End Sub