Hi this is my first post, I've not coded for some time until recently so my vba Knowledge may be a little rusty and not upto date with the newest versions of Excel.
I have a userform with dependant comboboxes, textbox, date etc that works great, but the sheet names are hardcoded. (see below code)
Private Sub cmbSubmit_Click()
Dim thissheet As Worksheet
If cmbType.Value = "Fruit" Then
Set thissheet = ThisWorkbook.Sheets("Fruit Exp") ' ("Fruit Exp") sheet To be write to if cmbType.value = Fruit
ElseIf cmbType.Value = "Vegetable" Then
Set thissheet = ThisWorkbook.Sheets("Vegetable Exp")
ElseIf cmbType.Value = "Fish" Then
Set thissheet = ThisWorkbook.Sheets("Fish Exp")
ElseIf cmbType.Value = "Other" Then
Set thissheet = ThisWorkbook.Sheets("Other Exp")
Else
MsgBox "Please choose an Expense Type!", vbOKOnly + vbExclamation
End If
' More code that writes to the sheet.
End Sub
I wish to change the hard coding ("Fruit Exp") that sets the active sheet to the same name as selected in the cmbType .
Should I try case function?
I hope I've explained the problem clearly enough.
Thank you in advance for any help you can offer.
Cheers
MaxSheets
Update.
I've Changed this code line and similar, {ThisWorkbook.Worksheets("Data").Range("A1")}
this eliminates one of the hard coded name values.
If cmbType.Value = ThisWorkbook.Worksheets("Data").Range("A1") Then
Set thissheet = ThisWorkbook.Sheets("Fruit")
Bookmarks