【发布时间】:2018-07-25 23:01:14
【问题描述】:
我目前正在尝试实现插入新行值和自动复选框插入器。
我目前有以下代码分布在不同的按钮上,因此也有不同的 Subs。我已将需要增加 1 个单元格的关键信息加粗。这将在单击“InsertNewBill”按钮后发生。:
Private Sub InsertNewBill_Click()
'I AM USING i TO STORE THE CELL INCREMENT, IT CURRENTLY DOES NOTHING**
Dim i As Integer
'**range("A30:AC30").Select**
'**range("AC30").Activate**
Selection.Copy
Selection.Insert Shift:=xlDown
End Sub
Private Sub DeleteTickBoxes_Click()
'Variables
Dim c As CheckBox
Dim CellRange As Range
Dim cel As Range
Set CellRange = ActiveSheet.Range("E7:**F30**")
'Delete Checkboxes within the specified range above on the ActiveSheet Only
For Each c In ActiveSheet.CheckBoxes
If Not Intersect(c.TopLeftCell, CellRange) Is Nothing Then
c.Delete
End If
Next
'Insert New Checkboxes and Assign to a specified link cell using the offset
For Each cel In CellRange
'you can adjust left, top, height, width to your needs
Set c = ActiveSheet.CheckBoxes.Add(cel.Left, cel.Top, 30, 6)
With c 'Clears the textbox so it has no text
.Caption = ""
'Offset works by offsetting (Row offset, Column Offset) and accepts
'positive for down/right and negative for left/up,
'keep in not that the linked cells will automatically populate with true/false
.LinkedCell = cel.Offset(0, -4).Address
End With
Next
Call CentreCheckbox_Click
End Sub
我需要所有加粗的值都加一。即从 F30 到 F31 和 A30:AC30 到 A31:AC31。 这个值也需要从 InsertNewBill_Click 子传递到 DeleteTickBoxes_Click 子。
我假设我需要删除 Private 子并且可能有一个公共整数变量? 我只是不确定如何在每次单击按钮后仅将数字增加 1。
感谢您的所有帮助
【问题讨论】:
-
遍历范围内的单元格并执行
MyCell.Value = MyCell.Value + 1? -
我正在考虑将 DeleteTickBox 和 InsertNewBill 子组合在一起,以允许整数增量的结转。这样我就可以在按下一个按钮的情况下完成所有这一切。我只是想看看我是否可以整理出整数增加
-
@tigeravatar 如果我要将单元格值增加 1。那么我将如何引用
range("A30:AC30").Select。我很抱歉,我对此比较陌生