First time poster here and I'm pretty inexperienced with VBA as you'll probably be able to tell.
I have an Excel UserForm ("UserFormEdit") that has a TextBox (TextBox1) and a ComboBox ("HolidaySelect"). In a table ("Holiday") I need obtain the number (Column 1) that corresponds to the string (Column 2) selected in the ComboBox ("HolidaySelect"). I then need to take that number and replace a number in my table "Index" that corresponds to the name from "TextBox1".
The two tables are both on Sheet1. ["Holiday" Table]:

["Index" Table:]Column 1 contains the names (to match TextBox1) Column 4 contains a number (this number needs to change to the number in the "Holiday" Table column 1 that is referenced by the holiday listed in column 2[obtained from ComboBox1]).
My UserForm is called "UserFormEdit"
With my code I get: Run-time error '9': Subscript out of range.
Thanks in advance for any help!
This is what I've been trying to get to work:
Private Sub ButtonSave_Click()
If MsgBox("Confirm the change?", vbYesNo, "Save record") = vbYes Then
Call WriteToSheet
Else: Unload Me
End If
End Sub
Public Sub WriteToSheet()
Dim tbl As ListObject
Set tbl = Sheet1.ListObjects("Holiday")
Dim lookupRng As Range
Set lookupRng = tbl.ListColumns(2).DataBodyRange
Dim returnRng As Range
Set returnRng = tbl.ListColumns(1).DataBodyRange
Dim holidayValue As Integer
holidayValue = Application.WorksheetFunction.XLookup(UserFormEdit.HolidaySelect.Value, lookupRng, returnRng, "")
Dim tbl2 As ListObject
Set tbl2 = Sheet1.ListObjects("Index")
Dim lookupRng2 As Range
Set lookupRng2 = tbl2.ListColumns(1).DataBodyRange
Dim returnRng2 As Range
Set returnRng2 = tbl2.ListColumns(4).DataBodyRange
Dim holidayNumber As Integer
holidayNumber = Application.WorksheetFunction.XLookup(UserFormEdit.TextBox1.Value, lookupRng2, returnRng2, "")
holidayNumber = holidayValue
End Sub
This worked for me: