简体   繁体   English

如何从特定单元格中删除按钮?

[英]How to delete button from a specific cell?

I have a log with several entries.我有一个包含多个条目的日志。 I enter additional data into a row, for example into cell "G3".我将附加数据输入一行,例如单元格“G3”。

If the entered data is a valid date, a button is created in a neighboring cell "J3" of that row如果输入的数据是有效日期,则会在该行的相邻单元格“J3”中创建一个按钮

Public Sub Worksheet_Change(ByVal target As Range)
    Dim intersection As Range
    Dim RgBtn As Range
    Dim Btn As Shape
    Dim wS As Worksheet
    Set intersection = Intersect(target, Columns(7))
    Set wS = ThisWorkbook.Sheets("Log")    'Worksheet

    If Not intersection Is Nothing Then

        If IsDate(target.Value) Then
            'MsgBox "Cell " & Target.Address(0, 0) & " contains a valid date."
            'Add Button:
            wS.Unprotect "DoNotChange!"
            Set RgBtn = wS.Range("J" & target.row)
            Set Btn = wS.Shapes.AddFormControl(xlButtonControl, RgBtn.Left, RgBtn.Top, RgBtn.Width, RgBtn.Height)
            With Btn
                .OnAction = "'CreateInvoice " & target.row & "'"
                .OLEFormat.Object.Text = "Create Entry"
            End With
        Else
            'MsgBox "Error..."
        End If

    End If
End Sub

When I click that button, data from that range(A3:F3) is copied to another sheet.当我单击该按钮时,该范围(A3:F3)中的数据被复制到另一张纸上。

I want, after clicking on that button, the button is deleted and replaced by the text "completed".我希望,在单击该按钮后,该按钮被删除并替换为“已完成”文本。

I tried several approaches to deleting that button.我尝试了几种删除该按钮的方法。

You can hide the button.您可以隐藏按钮。

With btn
    .Visible = Not .Visible
End with

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 VBA 从特定单元格中删除复选框 - Delete checkbox from a Specific Cell with VBA 如果单元格包含VBA / Excel中的特定值,如何从范围中删除列 - How to delete column from range if cell contains specific value in VBA/Excel 创建Excel VBA以从一栏中的单元格中删除特定文本 - Create Excel VBA to delete specific text from cell in one column 从 Excel 细胞向后计数中删除特定数字字符 - Delete specific numbers characters from Excel cell counting backwards Excel:如何创建快捷方式/浮动按钮以从工作表中的任何位置填充特定单元格? - Excel: How to create a shortcut/floating button to fill a specific cell from anywhere in the sheet? 如何删除Excel中特定范围内的所有单元格值? - How can I delete all cell values at a specific range in Excel? 如何使用excel公式删除1列中每个单元格的特定字符 - How to delete specific characters per cell in 1 column, using excel formulas 如何删除单元格包含特定结束字母的行? - How to delete rows where cell contains a specific end letter? 第二次出现特定字符后,如何删除单元格中字符串的一部分? - How to delete a part of a string in a cell after a second occurence of a specific character? 如何在excel vba中删除具有特定值的每个单元格? - How can I delete every cell with a specific value in excel vba?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM