用户表单在单击时更新最后一行编号

User form update the last row number on click

我正在尝试制作一个包含大约 50 个文本框的用户窗体。除了第一个文本框之外的所有文本框都采用数字或 vbNullString。 用户窗体根据文本框中的数字在列中输入相同的文本。例如,如果用户在 RC924TB 文本框中输入 4,表单将用 UL924 文本填充列中的 4 个单元格,然后移至下一个文本框。 我试图找出如何在根据文本框值填充多个单元格后更新 inputRange。到目前为止,这是我所拥有的,但是使用每个文本框中的值的总和来抵消 inputRange 会变得非常混乱。 有人可以提供更 eloquent 的解决方案吗?

Private Sub SubmitBtn_Click()

Dim inputRange As Range
     
            
    'Checks if room name has been inputted

If roomNameTB.Value = vbNullString Then
    MsgBox "Please add Room Name"
    roomNameTB.SetFocus
Else
End If


    ' find last row and add 2
Set inputRange = ActiveSheet().Cells(Rows.Count, 2).End(xlUp).Offset(2)
    
    
    
    'inputs room name
inputRange.Offset(0, 1).Value = roomNameTB.Value



    'inputs bridge 1
inputRange.Offset(0, -1).Value = "Bridge"


    ' inputs UL924 devices
If RC924TB.Value = vbNullString Then 'do nothing

    Else
        inputRange.Offset(1, -1).Resize(RC924TB.Value).Value = "UL924"
End If


' inputs RC1RTB devices
If RC1RTB.Value = vbNullString Then 'do nothing

    Else
        inputRange.Offset(RC924TB.Value + 1, -1).Resize(RC1RTB.Value).Value = "1R"
End If


End Sub

将值 UL9241R 等放入相关文本框的 ControlTipText

Private Sub SubmitBtn_Click()

    Dim c As Control, s As String
    Dim n As Long, rowIn As Long
    
    'Checks if room name has been inputted
    If RoomNameTB.Value = vbNullString Then
        MsgBox "Please add Room Name"
        RoomNameTB.SetFocus
        Exit Sub
    End If

    ' find last row and add 2
    rowIn = Cells(Rows.Count, "A").End(xlUp).Row + 2
    
    'inputs bridge1 and room name and bridge 1
    Cells(rowIn, "A") = "Bridge"
    Cells(rowIn, "C") = RoomNameTB.Value
    rowIn = rowIn + 1
   
    For Each c In Me.Controls
        If TypeName(c) = "TextBox" Then
            If c.Name Like "RC*" And IsNumeric(c.Value) Then
                
                n = c.Value
                If n > 0 Then
                    s = c.ControlTipText '"UL" & Mid(c.Name, 3, 3)
                    Cells(rowIn, "A").Resize(n).Value = s
                    rowIn = rowIn + n
                End If
                
            End If
        End If
    Next

End Sub