Execl2003将单元格变成下拉框并且补充Sheet2的数据

'Execl打开执行
Private Sub Workbook_Open()
    Dim selectStr As String
    Dim selectCellNum As Integer
    '获取Sheet2的A列有效行数
    selectCellNum = Sheets("Sheet2").[A65536].End(xlUp).Row
    '拼接Sheet2的RFID下拉框数据
    For Each c In Application.ThisWorkbook.Sheets("Sheet2").Range("A1:A" & selectCellNum)
        selectStr = selectStr & c.Value & ","
    Next
    'Sheet1的B列变成下拉框
    With Sheets("Sheet1").Range("B:B").Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=selectStr
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = ""
    .InputMessage = ""
    .ErrorMessage = "请选择下拉框内的RFID产品!"
    .ShowInput = True
    .ShowError = True
    End With
    
End Sub

 

注:

期间出现

 

 

 

 

后面群里大神帮助找到问题,问题是因为文件收到保护了,需要解除【保护工作薄】

 

 

 

感谢:https://blog.csdn.net/suxiaoli050421132/article/details/6700745

 

posted @ 2021-01-18 16:40  蜗牛的礼物  阅读(138)  评论(0编辑  收藏  举报