Hi,
I have created a macro that shows three inputboxes.
Inputbox 1: The user should enter a numerical value
Inputbox 2: The user shold enter a month
Inputbox 3: The user should select a range of cells that are going to be copied in the sheet
I would like the macro to delete a specific cell value (the one which the user has entered in inputbox 2) if the user clicks on cancel in inputbox 3.
How can i do this?
Any input is much appreciated!
Sub GegevensInvoeren()
Dim rngCopyFrom As Range
Dim iCode As String 'code 88 of 89
Dim strFactuurMaand As String 'Jaar-Mnd
'invoer periode in bovenste rij
iCode = InputBox("Voer in code: 88 of 89", "Invoer UWV gegevens")
strFactuurMaand = InputBox("Voer de factuurmaand in volgens het format ""20XX-XX""", _
"Invoer UWV gegevens")
If strFactuurMaand <> Format(strFactuurMaand, "yyyy-mm") Then
MsgBox "U heeft geen geldige factuurmaand ingevuld." _
& vbCrLf & "Vul de factuurmaand in volgens de notatie ""20XX-XX""." _
& vbNewLine & vbNewLine & "Bijvoorbeeld: voor de factuurmaand ""juli 2020"" vult u in: ""2020-05""." _
, vbCritical, "Invoer UWV gegevens"
If strFactuurMaand <> Format(strFactuurMaand, "yyyy-mm") Then Exit Sub
End If
'afbreken geen inkomen ingevuld
If iCode = "" Then
MsgBox "U hebt nog geen inkomen ingevuld.", vbCritical, _
, "Inkomen invoeren"
Exit Sub
End If
'afbreken geen geldige code ingevuld
If iCode <> 88 And iCode <> 89 Then
MsgBox "U heeft geen geldige code ingevuld.", vbCritical, "Invoer UWV gegevens"
Exit Sub
End If
If iCode = 88 Then
Worksheets("test1").Range("H1").End(xlDown).Offset(1, 0) _
= strFactuurMaand
End If
If iCode = 89 Then
Worksheets("test2").Range("M1").End(xlDown).Offset(1, 0) _
= strFactuurMaand
End If
'ínvoer cellen extern sheet
On Error Resume Next
Set rngCopyFrom = Application.InputBox("Selecteer de cellen die u wilt invoegen.", _
Type:=8)
On Error GoTo 0
If Not rngCopyFrom Is Nothing Then
If iCode = 88 Then
rngCopyFrom.Copy (Worksheets("test1").Range("A1").End(xlDown).Offset(1, 0))
End If
If iCode = 89 Then
rngCopyFrom.Copy (Worksheets("test2").Range("B1").End(xlDown).Offset(1, 0))
End If
End If
End Sub
Bookmarks