Как получить серийный номер от пользователя в Excel - PullRequest
0 голосов
/ 09 июля 2020
Private Sub CommandButton1_Click()
Dim a As String, bInvalid As Boolean, CurrDate As Date
CurrDate = Date
  a = InputBox("Enter the Row", "Please enter the row number", "Please enter data")
  If IsNumeric(a) Then
    If a > 0 Then
      Rows(a).Select
          Selection.Copy
          Selection.Insert Shift:=xlDown
          Cells.EntireColumn.AutoFit
          Range("L" & a).ClearContents
          Rows(a + 1).Select
          Range("S" & a).Value = CurrDate + 1
          Selection.Rows.Group
          ActiveSheet.Outline.ShowLevels RowLevels:=1
    Else
      bInvalid = True
    End If
  Else
    ' If the user presses Cancel, then a=""
    If a <> "" Then bInvalid = True
  End If
  If bInvalid Then MsgBox "Please enter a valid row number"
End Sub

введите описание изображения здесь

В настоящее время я принимаю ввод строк от пользователя, но, как вы можете видеть на изображении, я хочу использовать sr.no как ввод от пользователя, например c1, c2, так что есть ли как приведенный выше код можно изменить и работать с вводом sr.no, а не со строкой?

Ответы [ 2 ]

0 голосов
/ 09 июля 2020
Private Sub CommandButton1_Click()
Dim a As String, bInvalid As Boolean, CurrDate As Date, X As Integer
CurrDate = Date
a = InputBox("Enter the RFI number", "Please enter the RFI number", "Please enter data")
    Cells.Find(What:=a, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
    X = ActiveCell.Row
    Rows(X).Select
    Selection.Copy
    Selection.Insert Shift:=xlDown
    Range("L" & X).ClearContents
    Rows(X + 1).Select
    Selection.Rows.Group
    ActiveSheet.Outline.ShowLevels RowLevels:=1

End Sub

Это работает. Спасибо.

0 голосов
/ 09 июля 2020
Private Sub CommandButton1_Click()
Dim a As String, bInvalid As Boolean, CurrDate As Date
CurrDate = Date
a = InputBox("Enter the RFI number", "Please enter the RFI number", "Please enter data")
    Cells.Find(What:=a, After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False).Activate
    Rows(a).Select
    Selection.Copy
    Selection.Insert Shift:=xlDown
    Range("L" & a).ClearContents
    Rows(a + 1).Select
    Selection.Rows.Group
    ActiveSheet.Outline.ShowLevels RowLevels:=1

End Sub

Я получаю сообщение об ошибке в строках (a). Выберите, застрял здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...