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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.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 Excel案例查询_Excel_Vba - Fatal编程技术网

带组合框和形状复制的VBA Excel案例查询

带组合框和形状复制的VBA Excel案例查询,excel,vba,Excel,Vba,我试图使我的组合框下拉列表功能 我想在另一张图纸中增加单元格+1中的值,并立即从另一张图纸复制形状 我这样写代码: Private Sub ComboBox1_Change() Dim rng As Range Dim picName As String Set rng = ActiveSheet.Range("B65") picName = "Firestop" Select Case rng Case "CFS-PL 107" Worksheets("hilti f

我试图使我的组合框下拉列表功能

我想在另一张图纸中增加单元格+1中的值,并立即从另一张图纸复制形状

我这样写代码:

 Private Sub ComboBox1_Change()
 Dim rng As Range
 Dim picName As String
 Set rng = ActiveSheet.Range("B65")

 picName = "Firestop"

 Select Case rng

 Case "CFS-PL 107"

 Worksheets("hilti firestopping stores").Range("E5").Value = Range("E5") + 1
 Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy
 ActiveSheet.Range("L24").PasteSpecial Name = "Firestop"

 End Select
 End Sub
 With Sheets("hilti firestopping stores").Range("E5")  'Cell value incrementation by 1
            .Value = .Value + 1       
        End With
    Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy ' copying the shape from another sheet
    ActiveSheet.Range("L24").PasteSpecial   'paste the shape in the target sheet
    Selection.Name = "Firestop"   'instant rename the shape pasted, while is still selected
我这里基本上有两个问题:

  • 单元格“E5”中的值最多只增加1。如果我选择这种情况,它仍然是1,而当我设置+1增量时,它应该是2
  • 对象(图像)被正确地复制,尽管我想给它们设置一些唯一的名称,而不是“Picture…”,下一步的排序与“Picture”的编号相同
  • 这里的问题是: 无法解决我的问题,因为没有关于形状id递增顺序的信息。 我在这里发现了类似的东西:

    并尝试在我的代码中使用:

     Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy
     ActiveSheet.Range("L24").PasteSpcial
     With .Shapes(.Shapes.Count)
     .Name = "Firestop"
     End With
    
    但我得到了一个错误: **

    编译错误:引用无效或不合格

    **


    有人能告诉我问题出在哪里吗?

    我的代码应该是这样的:

     Private Sub ComboBox1_Change()
     Dim rng As Range
     Dim picName As String
     Set rng = ActiveSheet.Range("B65")
    
     picName = "Firestop"
    
     Select Case rng
    
     Case "CFS-PL 107"
    
     Worksheets("hilti firestopping stores").Range("E5").Value = Range("E5") + 1
     Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy
     ActiveSheet.Range("L24").PasteSpecial Name = "Firestop"
    
     End Select
     End Sub
    
     With Sheets("hilti firestopping stores").Range("E5")  'Cell value incrementation by 1
                .Value = .Value + 1       
            End With
        Worksheets("hilti firestopping stores").Shapes("Firestop_Plug").Copy ' copying the shape from another sheet
        ActiveSheet.Range("L24").PasteSpecial   'paste the shape in the target sheet
        Selection.Name = "Firestop"   'instant rename the shape pasted, while is still selected
    

    然后我把这两个问题都整理好了。在选择案例时,我的图像到达目标工作表,并且母单元格中的值会自动更改。

    设置rng=…
    将rng设置为字符串
    ^请不要将rng设置为字符串,这非常混乱。它起作用了,现在我更新了查询,问题是,我在目标工作表中的值只更改了一次。我应该为我的单元格使用另一个递增+1的代码吗?我一般都更改了查询。你的建议很好,但我还有两个问题要解决。