限制行数以记录特定数量的消息

时间:2019-06-17 17:22:52

标签: excel vba

关于此问题,我如何在行中设置一定数量的限制(例如:100)以使用vba-excel记录记录,同样,当计数超过时应显示一条消息并防止其记录新记录。

有人可以帮我修改代码吗?

Sub Captura_ficha()
   Dim TransRowRng As Range
   Dim NewRow As Integer
   Dim i As Integer
   Dim Valor As String
   Dim Valor1 As String
   Dim RwLast As Long

   strTitulo = "Ficha de registro"

   For i = 1 To 5
       If Sheets("REGISTRO").Range("ficha" & i).Value = "" Then
           Valor = Sheets("REGISTRO").Range("ficha" & i).AddressLocal
           Valor1 = Valor1 & vbNewLine & Valor
       End If
   Next i

   RwLast = Range("A100").End(xlUp).Row

   If RwLast < 100 Then
       Set TransRowRng = ThisWorkbook.Worksheets("LISTA").Cells(1, 1).CurrentRegion
       NewRow = TransRowRng.Rows.count + 1
       With ThisWorkbook.Worksheets("LISTA")
          .Cells(NewRow, 1).Value = [ficha0]
          .Cells(NewRow, 2).Value = [ficha2]
          .Cells(NewRow, 3).Value = [ficha3]
          .Cells(NewRow, 4).Value = [ficha4]
          .Cells(NewRow, 5).Value = [ficha5]
       End With
       MsgBox "SE GRABÓ CORRECTAMENTE.", vbOKOnly + vbInformation, strTitulo
    Else
       MsgBox "HA LLEGADO EL LIMITE DE REGISTRO. POR FAVOR NOTIFIQUE AL ADMINISTRADOR", vbOKOnly + vbInformation, strTitulo
    End If
End Sub

0 个答案:

没有答案