I keep running into the error message "Object Variable or With Block Variable Not Set", however, when I use SET to set the variable then I get the same error despite having set it. Does anyone know why this may be happening? This is my code I have and the line that keep throwing the two errors is
name = sht.Range("A1:Z2").Find(What:=colname, Lookat:=xlWhole, LookIn:=xlFormulas, MatchCase:=True)
The error gets thrown so early that the code cannot even try running getdata so I have not yet been able to debug that to see if it works entirely. Before calling getdata, the function getcolumnindex runs fine. Here is my entire code
Public Sub Main() 
Dim wb As Workbook, ws As Worksheet, i As Range, dict As Object, wbSrc As Workbook 
Dim value As Long 
Set wb = ThisWorkbook 
Set ws = wb.Worksheets("Sheet1") 
Set dict = CreateObject("scripting.dictionary") 
For Each i In ws.Range("E2:E15").Cells 
 sysnum = i.value 
 sysrow = i.Row 
 syscol = i.Column 
getcolumnindex ws, "Range (nm)" 
value = getdata(sysrow, "Range (nm)") 
Next i 
End Sub 
Function getcolumnindex(sht As Worksheet, colname As String) As Integer 
Dim name As Range, colind As Integer 
## Error gets thrown at this line below 
Set name = sht.Range("A1:Z2").Find(What:=colname,Lookat:=xlWhole, LookIn:=xlFormulas, MatchCase:=True) 
   If Not name Is Nothing Then 
        colind = name.Column 
        MsgBox name & " column index is " & colind 
   End If
End Function 
Function getdata(WDrow As Integer, parametercol As String) 
Dim cell As Variant, ws As Worksheet 
cell = getcolumnindex(ws, "Tuning Range (nm)") 
Data = Cells(WDrow, parametercol) 
MsgBox (Data) 
End Function
