So it seems like this should be simple beyond belief, but regrettably excel doesn't agree, and multiple online searches have failed to produce solutions that work. I have two tables that I need to add and remove names from by pushing corresponding buttons, which bring up a prompt for the name to be entered in. If the user pushes 'Cancel', I just need the macro to exit. My If statement works if the user inputs and empty string, but if they push cancel it populates a 'False' cell to the table, instead of exiting.
I have tried such code as:
If newName = "" Then
Exit Sub
ElseIf newName = False Then
Exit Sub
End If
But the ElseIf statement fails due to type mismatch. Here is my code for adding to the table as it stands:
Sub add()
Dim newName As String, newRow1 As Object, newRow2 As Object
newName = Application.InputBox(Prompt:="Input name in format of LNAME, FNAME", Type:=2)
If newName = "" Then
Exit Sub
End If
Set newRow1 = ActiveSheet.ListObjects("Table1").ListRows.Add(AlwaysInsert:=True)
newRow1.Range.Cells(, 1).Value = newName
Set newRow2 = ActiveSheet.ListObjects("Table3").ListRows.Add(AlwaysInsert:=True)
newRow2.Range.Cells(, 1).Value = newName
End Sub
All help is greatly appreciated.
Bookmarks