【发布时间】:2018-07-25 15:07:47
【问题描述】:
由于我对最后一个问题不太清楚。我是新手,在如何实施任何答案方面需要一些指导。
我目前有以下代码分布在不同的按钮上,因此分布在不同的 Subs 上。为了清楚起见,我将需要从代码中递增 1 的范围分开,并将每次按下按钮时我需要递增 1 的值加粗。我很欣赏这打破了格式,我道歉。
点击“InsertNewBill”按钮后数量会增加:
Private Sub InsertNewBill_Click()
'I AM USING i TO STORE THE CELL INCREMENT, IT CURRENTLY DOES NOTHING**
Dim i As Integer
范围("A30:AC30").选择
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
设置 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。
感谢您的所有帮助
【问题讨论】:
-
假设你所有的代码都在同一个模块中?在模块顶部声明一个公共变量(即
Public iRowNum as Long)。您可以将此变量设置为行号并在您的代码中使用它(即Range("A" & iRowNum & ":AC" & iRowNum).Copy) -
@Zac 谢谢!我会看看我能实现什么。所有代码都在同一个模块中。