Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 在一个MsgBox VBA中显示所有数组元素值_Arrays_Excel_Vba_Msgbox - Fatal编程技术网

Arrays 在一个MsgBox VBA中显示所有数组元素值

Arrays 在一个MsgBox VBA中显示所有数组元素值,arrays,excel,vba,msgbox,Arrays,Excel,Vba,Msgbox,请遵守我的密码。(我不是一个好的程序员,也不熟悉所有VBA语法。) 我正在为我们所有的家庭书籍建立一个数据库 我没有使用ACCESS或SQL,只是简单地将所有UserForm输入数据记录到Excel工作表中 在我的用户表单中,所有的数据都是通过一个组合框输入的,这些数据有一个类别,比如:作者、流派、出版商、书在家里的位置等等 每个组合框的初始行源是excel工作表中的一个范围。在这个范围内,我已经为每个类别输入了一些项目。因此,在执行宏时,单击每个组合框的下拉箭头时,将显示列表项 下面代码中的“

请遵守我的密码。(我不是一个好的程序员,也不熟悉所有VBA语法。)

我正在为我们所有的家庭书籍建立一个数据库

我没有使用ACCESS或SQL,只是简单地将所有UserForm输入数据记录到Excel工作表中

在我的用户表单中,所有的数据都是通过一个组合框输入的,这些数据有一个类别,比如:作者、流派、出版商、书在家里的位置等等

每个组合框的初始行源是excel工作表中的一个范围。在这个范围内,我已经为每个类别输入了一些项目。因此,在执行宏时,单击每个组合框的下拉箭头时,将显示列表项

下面代码中的“Private Sub CmdEditList_Click()”功能首先是,如果在现有列表中找不到每个组合框中的数据,则更新每个类别中的项目列表。第二,更新每个组合框的行源

下面的MsgBox代码行(我在其中遇到了一个问题)的目的是通知用户哪些类别的项目已添加到其列表中`

MsgBox "The following Categories were updated:" & vbNewLine & msg` 
但在更新3个类别(Author、Publisher和Series)的情况下,不会显示Author和Publisher,而是在2行换行后,只显示“Series”

问题的原因是什么?解决办法是什么

    Private Sub CmdEditList_Click()

Dim NextListRow As Long
Dim ComboArr()
Dim RangeArr()
Dim MsgBoxArr()
Dim CategoryArr()
Dim i As Integer
Dim UpdateItemCnt As Integer
Dim mbi As Integer

Const LASTINDEX = 8

i = 0
UpdateItemCnt = -1

ComboArr = Array(ComboAuthor, ComboGenre, ComboPublisher, _
                 ComboLocation, ComboSeries, ComboPropertyOf, _
                 ComboRating, ComboRatedBy, ComboStatus)
RangeArr = Array("R", "S", "T", "U", "V", "W", "X", "Y", "Z")
CategoryArr = Array("Author", "Genre", "Publisher", "Location", "Series", _
                    "Property Of", "Rating", "Rated By", "Status")

    Do While i <= LASTINDEX
        'Checks each Combobox, if ther's a data input.
        If Len(Trim(ComboArr(i).Value)) <> 0 Then

            Set wkb = ThisWorkbook
                wkb.Sheets("Database").Activate
            With ActiveSheet
                'Finds the cell, where a new item of a Category can be placed in the excel sheet.
                NextListRow = .Cells(.Rows.Count, RangeArr(i)).End(xlUp).Row + 1
            End With

            'Check if the entered data is not in the existing list.
            'If True, ComboBox data is in the list.
            If Application.CountIf(Range(RangeArr(i) & "2" & ":" & RangeArr(i) & NextListRow), _
                                   ComboArr(i).Value) > 0 Then
                GoTo NextRoutine
            Else
                UpdateItemCnt = UpdateItemCnt + 1
                ReDim MsgBoxArr(UpdateItemCnt)
                MsgBoxArr(UpdateItemCnt) = CategoryArr(i)

                MsgBox MsgBoxArr(0) 'To Check the value of MsgBoxArr(0) after 2nd assignment.
                                    'Upon checking via debug simulation, the value = "".

                'Assigns the ComboBox Value under its corresponding Category in excel sheet.
                Database.Cells(NextListRow, RangeArr(i)).Value = ComboArr(i).Value

                'Refreshes the range of the list to be displayed via the ComBox dropdown arrow.
                Range(RangeArr(i) & "2", Range(RangeArr(i) & Rows.Count).End(xlUp)).Name = "Dynamic"
                ComboArr(i).RowSource = "Dynamic"
            End If
NextRoutine:
        Else
            GoTo EndRoutine
EndRoutine:
        End If
        i = i + 1
    Loop

    MsgBox MsgBoxArr(0) 'To Check the value of MsgBoxArr(0) after loop.
                        'Upon checking via debug simulation, the value = "".

    For mbi = LBound(MsgBoxArr) To UBound(MsgBoxArr)
        msg = msg & MsgBoxArr(mbi) & vbNewLine
    Next mbi

    MsgBox "The following Categories were updated:" & vbNewLine & msg
    'In cases, wherein new item for Author, Publisher and Series were input in the UserForm,
    'the MsgBox only shows: The following Categories were updated:
    '
    '
    '                       Series

End Sub
Private Sub CmdEditList_Click()
暗淡的下一行与长
Dim ComboArr()
Dim RangeArr()
Dim MsgBoxArr()
Dim CategoryArr()
作为整数的Dim i
Dim UpdateItemCnt作为整数
作为整数的Dim mbi
常数LASTINDEX=8
i=0
UpdateItemCnt=-1
ComboArr=数组(ComboAuthor、ComboGenre、ComboPublisher、_
ComboLocation、ComboSeries、ComboPropertyOf、_
ComboRating,ComboRatedBy,ComboStatus)
RangeArr=数组(“R”、“S”、“T”、“U”、“V”、“W”、“X”、“Y”、“Z”)
CategoryArr=数组(“作者”、“流派”、“出版商”、“位置”、“系列”_
“财产”、“评级”、“评级人”、“状态”)
趁我还活着的时候
应该是

ReDim Preserve MsgBoxArr(UpdateItemCnt)

如果在不保留的情况下调整数组大小,则任何现有内容都将丢失

是否为多选组合框?否。我支持多选。
ReDim Preserve MsgBoxArr(UpdateItemCnt)