Hvis "Cancel" vælges:
Sub SkrivICelle2()
Dim userInput As String
On Error GoTo Fejl:
If Not ActiveCell = "" Then Exit Sub
userInput = InputBox("Skriv dit input her:", "Skriv her")
If userInput = vbNullString Then Exit Sub
userInput = Format(Date, "dd.mm.yy") & " " & Application.UserName & " " & userInput
ActiveCell.Value = userInput
Columns("D:D").EntireColumn.AutoFit
Exit Sub
Fejl:
MsgBox "Fejl"
End Sub
Prøv evt. denne, hvor man kan tilføje tekst:
Sub SkrivICelle3()
Dim userInput As String
On Error GoTo Fejl:
If Not ActiveCell = "" Then
userInput = InputBox("Skriv dit input her:" & vbLf & _
vbLf & "Teksten vil blive tilføjet efter:" & vbLf & _
vbLf & ActiveCell, "Skriv her")
If userInput = vbNullString Then Exit Sub
userInput = ActiveCell & " " & userInput
ActiveCell.Value = userInput
GoTo Indsæt:
End If
userInput = InputBox("Skriv dit input her:", "Skriv her")
If userInput = vbNullString Then Exit Sub
userInput = Format(Date, "dd.mm.yy") & " " & Application.UserName & " " & userInput
Indsæt:
ActiveCell.Value = userInput
Columns("D:D").EntireColumn.AutoFit
Exit Sub
Fejl:
MsgBox "Fejl"
End Sub