I need to find the end of a list and then skip to the next cell and enter "Question " + k
. Where k
is the number of cells with text so far in the column. The worksheet should look like this:
Question 1
Question 2
-------------> Here insert "Question " + count of non-empty cells (Which should return Question 3)
Here is my code in full:
Option Explicit
Private Sub cmdbtnAddQuestion_Click()
Worksheets("QuestionsToAnswerBucket").Activate
If IsEmpty(Range("A7")) Then
Range("A7").Activate
ActiveCell = "Question 1"
ElseIf IsEmpty(Range("B8")) Then
Range("A8").Activate
ActiveCell = "Question 2"
ElseIf IsEmpty(Range("B9")) Then
Range("A9").Activate
ActiveCell = "Question 3"
ElseIf IsEmpty(Range("B10")) Then
Range("A10").Activate
ActiveCell = "Question 4"
ElseIf IsEmpty(Range("B11")) Then
Range("A11").Activate
ActiveCell = "Question 5"
ElseIf IsEmpty(Range("B12")) Then
Range("A12").Activate
ActiveCell = "Question 6"
Else
Worksheets("QuestionQueue").Activate
k = Application.WorksheetFunction.CountIf(Range("A2:A200"), "*")
If IsEmpty(Range("A7")) Then
Range("A7").Activate
ActiveCell = "Question 1"
Else
Range("A7").End(xlDown).Offset(1, 0).Select
ActiveCell.Value = "Question " & (k + 1)
ActiveCell.Font.Bold = True
End If
End If
If txtAddAQuestion.Value = "" Then
MsgBox "Please Insert A Question"
Else:
ActiveCell.Offset(0, 1).Value = txtAddAQuestion.Value
ActiveCell.Font.Bold = True
End If
Unload Me
End Sub