根据工作表中的最后一个值自动更新文本框值

时间:2017-06-14 09:47:47

标签: excel vba excel-vba

enter image description here 我在工作表中有这些

enter image description here

然后在userform上,我希望当我更改章节时,编号部分自动更新,如果在工作表上,第1章最后编号是1,那么userform上的编号会自动更新为2,然后与第2章和第3章。

这就是我的尝试:

    Dim label As Control
    For ctr = 1 To InfoForm.Chapter.ListCount - 1
        For Each label In InfoForm.Controls
            If TypeName(label) = "Label" Then
                i = i + 1
                Dim WhatChapter As String
                WhatChapter = InfoForm.Chapter
                lastNum = Cells(.Rows.Count, "A").End(xlUp).Row
                If WhatChapter = "Chapter " & ctr Then
                    If Cells(lastNum, i).Value = "No." Then
                        Num.Value = 1
                    Else
                       Num.Value = Cells(lastNum, i).Value
                    End If
                End If
            End If
        Next
    Next ctr

0 个答案:

没有答案