I'm currently making an expense form but I'm struggling for a list of expense categories, I want to make it so that I can type the category I choose in an input box, that then goes in a list which is used as a data validation. I want the values to add into column A on Sheet2
I've tried the below so far
Sub Button1_Click()
Dim ExpenseName As String
ExpenseName = InputBox( _
"Type in the name of the category you want to add", _
"Add Expense Category", _
"Type expense category here")
If Len(ExpenseName) = 0 Then
MsgBox "No category chosen"
Exit Sub
End If
'**Struggling what to put here**
End Sub
I have added the below, please see.
Sub Button1_Click()
Dim ExpenseName As String
ExpenseName = InputBox( _
"Type in the name of the category you want to add", _
"Add Expense Category", _
"Type expense category here")
If Len(ExpenseName) = 0 Then
MsgBox "No category chosen"
Exit Sub
End If
Dim strList As String
Dim ws As Worksheet
Dim eRow As Long
eRow = Sheet2.Cells(Sheet2.Rows.Count, 1).End(xlUp).Row
With ThisWorkbook.Sheets("Sheet1").Range("D4:D21").Validation
.Delete 'Delete previous validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Formula1:="=Sheet2!$A$1:$A$" & eRow
End With
End Sub