Hello, I'm new to VBA. I'm trying to search row 5 of a sheet and after every time a cell contains the phrase "Skymaster", a new column is inserted to the right with a InputBox-specified name. I would then like to add a sheet to the workbook with the same InputBox-specified name. Here is the code I have so far; for some reason it works the first time, but after that I get a 1004 error.
Private Sub CommandButton1_Click()
Dim givenname
For a = 1 To ActiveSheet.Cells(5, Columns.Count).End(xlToRight).Column
If ActiveSheet.Cells(5,a).Value = "Skymaster" Then
ActiveSheet.Columns(a+1).Insert
givenname = InputBox("Enter Name of New Aircraft", "New Aircraft")
Cells(5, a + 1).Value = givenname
a = a + 1
End If
Next a
Dim WS As Worksheet
Set WS = Sheets.Add
Sheets.Add.Name = givenname
End Sub
Bookmarks