excel - 我的 "error of compatibilty"来自哪里?

标签 excel vba

我必须在 VBA 中编写一个小应用程序,用于学校。
对于这个应用程序,我需要在一些不同的列表框中添加项目,因为它与每个列表框的做法相同,我创建了一个带有参数的方法:我正在使用的工作表、我开始的列和我的列表框必须填写。

但是当我执行代码时,我有一个“类型兼容性错误”。我认为它来自我调用我的 sub 的那一行。但自从 3 天以来我没有找到纠正它的方法。

var 'cellulePrecedente' 代表单元格中之前迭代读取的文本,内容可以重复多次,所以我只添加与之前不同的类(class)名称。避免写两次相同的类(class)。

我也接受任何提示,因为我是 VBA 的初学者。

代码来了:

Private Sub UserForm_Initialize()
    ' On va appeler, pour chaque listbox a remplir la méthode d'initialisation
    Call Initialiser_ListBoxs("Cours Ig", "D", ListBox1)
End Sub

Private Sub Initialiser_ListBoxs(Feuille As String, ColonneDepart As String, ListBoxConcernee As ListBox)
    Dim CellulePrecedente As String
    ' On doit fournir la feuille dans laquelle on doit rechercher les éléments, la colonne de depart (si on fait les cours ou les ue
    ' Il faut aussi fournir la listbox a remplir
    Sheets(Feuille).Activate
    ' On sélectionne la cellule correspondant au point de départ (1er cours/1ere UE)
    ' La première ligne étant le titre de la colonne
    Range(ColonneDepart & "2").Select
    CellulePrecedente = ""
    ' On continue de parcourir tant que tous les cours/UE n'ont pas été lu(e)s
    While Range(ColonneDepart & ActiveCell.Row) <> ""
        ' On ne réécrit pas 2 fois le/la même cours/UE
        If CellulePrecedente <> Range(ColonneDepart & ActiveCell.Row) Then
            ListBoxConcernee.AddItem Range(ColonneDepart & ActiveCell.Row)
        End If
        CellulePrecedente = Range(ColonneDepart & ActiveCell.Row)
        Range(ColonneDepart & ActiveCell.Row + 1).Select
    Wend
End Sub

谢谢你的帮助 !

PS:我知道代码是用法语编写的,但我尽力解释它是如何工作的。我假设您可能不了解所有内容,请随时提出任何问题!

最佳答案

改变:

Private Sub Initialiser_ListBoxs(Feuille As String, ColonneDepart As String, _
                             ListBoxConcernee As ListBox)

至:
Private Sub Initialiser_ListBoxs(Feuille As String, ColonneDepart As String, _
                             ListBoxConcernee As MSForms.ListBox)

关于excel - 我的 "error of compatibilty"来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61218223/

相关文章:

arrays - 如何使用数组查找/替换选定单元格中的多个值?

excel - VBA Excel 中的弹出图表

sql - 检测某些记录是否被排除在 INSERT INTO 操作之外

Excel VBA循环文件夹并运行宏

internet-explorer - 使用 VBA 自动化 IE - 单击 Javascript 链接(无 anchor 标记)

excel - 编写 csv 以在 Excel 中作为不同的选项卡打开

excel - 如何选择 'or' 值?

excel - 从 Excel 2011 创建 Word 文件

vba - 如何在 vba 中添加库引用,以便每次打开新工作簿时它都保持添加状态?

vba - 通过 GetTickCount 获取代码运行时并以特定方式格式化它