Transcribe the result of an InputBox into a cell.

Solved
volfoss Posted messages 43 Status Member -  
volfoss Posted messages 43 Status Member -
Bonjour,
I created a macro but I would like to perform the following action. The response entered (which will only be a year in the format YYYY) in the InputBox must be written in cells B2:F2.
Additionally, how can I ensure that if we click cancel or on the cross, the InputBox closes without receiving the type mismatch error and runtime error 13?
Thank you for your help.

Sub CreateRings()
Dim Rep As Integer
If Rep = InputBox("Remember to enter the breeding season in B2", "Breeding season") Then 'The variable receives the value entered in the InputBox
If Rep = vbOK Then
' here the processing if positive response
ActiveCell.FormulaR1C1 = "" 'display the InputBox response
Selection.Copy
Range("B2:F2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
End If
Else
' here the processing if negative response
End If
End Sub

1 answer

  1. Gyrus Posted messages 3360 Status Member 526
     
    Hello,

    You can start with this code:
    Sub CreateRings()
    Dim Rep As String
    Rep = InputBox("Remember to enter the breeding season in B2", "Breeding season")
    If IsNumeric(Rep) Then Range("B2") = Rep
    End Sub

    See you!
    0
    1. volfoss Posted messages 43 Status Member 3
       
      Great
      I admire your programming talent, I am self-taught in this field but I don't always manage to program what I want to do, but thanks to your help I am making progress.
      0