【问题标题】:Adding activeX Combobox untill the last full line添加activeX Combobox直到最后一行
【发布时间】:2014-09-14 19:35:45
【问题描述】:

如何将 activeX 组合框添加到“列表名称”列中,直到网格的最后一行?知道在网格中唯一总是充满值的列是“C Type”

我试过这个:

For Each Ws In ActiveWorkbook.Sheets
        With Ws
            'adding the validation dropdown
             Col_num = .Range("A1").End(xlToRight).Column
             Set MyRange = .Range(.Cells(1, 1), .Cells(1, Col_num)).Cells.Find("List Name")
             Set FullRange = .Range(.Cells(1, 1), .Cells(1, Col_num)).Cells.Find("C Type")

             'LastLine = .Range(FullRange).End(xlDown).Row
             LastLine = .Cells(2, FullRange).End(xlDown).Row

            Do Until IsEmpty(LastLine)
                If Not MyRange Is Nothing Then
                    With Ws.Columns(MyRange.Column).Validation
                     .Delete
                     .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                      xlBetween, Formula1:=Liste
                      .IgnoreBlank = True
                      .InCellDropdown = True
                    End With
                End If
             Loop
        End With
    Next Ws

但它在此行中给出错误“对象_worksheet的方法范围失败”:

LastLine = .Range(FullRange).End(xlDown).Row 。 当我尝试以下操作时,它给了我错误“类型不匹配” LastLine = .Cells(2, FullRange).End(xlDown).Row

有人可以帮忙吗?

【问题讨论】:

    标签: excel combobox activex excel-2007 vba


    【解决方案1】:

    用途:

    LastLine = .Cells(.Rows.Count, FullRange.Column).End(xlUp).Row
    

    修改后的完整代码:

    For Each Ws In ActiveWorkbook.Sheets
        With Ws
            'adding the validation dropdown
            Col_num = .Range("A1").End(xlToRight).Column
            Set myrange = .Rows(1).Find("List Name")
            If Not myrange Is Nothing Then
                Set fullrange = .Rows(1).Find("C Type")
                If Not fullrange Is Nothing Then
                    'LastLine = .Range(FullRange).End(xlDown).Row
                    lastline = .Cells(.Rows.Count, fullrange.Column).End(xlUp).Row
    
                    With .Range(.Cells(2, myrange.Column), .Cells(lastline, myrange.Column)).Validation
                        .Delete
                        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                             xlBetween, Formula1:=Liste
                        .IgnoreBlank = True
                        .InCellDropdown = True
                    End With
                End If
            End If
        End With
    Next Ws
    

    【讨论】:

    • 我得到错误 91 对象变量或未设置块变量.. 这可能是 FullRange.column 的问题
    • 这意味着找不到'C Type'。它应该出现在所有工作表上吗?如果代码不存在该怎么办?
    • 不在工作簿的所有工作表中,但只要有 C 类型列,我需要添加组合框直到最后一行!请问有什么办法吗?
    • 试试我刚刚发布的修改版。
    • 嗯没有错误,但组合框仍然不在网格中:(
    猜你喜欢
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 2019-03-31
    • 1970-01-01
    相关资源
    最近更新 更多