我创建了一个包含多张工作表的工作簿。在其中一个工作表中,我编写了一个宏,一旦单击 active-x 按钮,它就会在另一个工作表(带有预定义的单元格)中创建下拉值。
现在的问题是,一旦我运行宏,它就会完美执行,但是一旦我删除宏,即使我在删除宏之前保存了文件,下拉值也会消失。
让我知道是否需要更多详细信息。
代码片段 -
Private Sub CommandButton1_Click()
'Define the variables
Dim vRangeDefined, vRowCount, vCounter, vCellValue As String, vDataValue As String
Dim wbk As Workbook
'Define the range where the values are entered
vRangeDefined = ActiveSheet.Range("A:B").Value
vRowCount = ActiveSheet.UsedRange.Rows.Count
For vCounter = 2 To vRowCount
vCellValue = vRangeDefined(vCounter, 1)
vDataValue = vRangeDefined(vCounter, 2)
'Assign the names to cells as per the range
Sheets(2).Select
ActiveSheet.Range(vCellValue).Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=vDataValue
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Next
MsgBox "Process complete..."
End Sub
谢谢!