maxicanfly
New Member
- Joined
- Jun 22, 2021
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hi everyone,
I am developing an excel VBA function that reads a value from another worksheet and workbook. I have done the debugging of it and the results is stored in the variable just fine, but in the excel cell, I get #Value!. This Value! issue triggers immediately after I call off the worksheet in the VBA code below. If I freeze that sentence(and bodge up the code), my function returns the set variable.
Set ws = src.Worksheets(ExcelWorksheet) once active triggers #Value! as output of the function in my cell. Can someone help me? thanks
I am developing an excel VBA function that reads a value from another worksheet and workbook. I have done the debugging of it and the results is stored in the variable just fine, but in the excel cell, I get #Value!. This Value! issue triggers immediately after I call off the worksheet in the VBA code below. If I freeze that sentence(and bodge up the code), my function returns the set variable.
Set ws = src.Worksheets(ExcelWorksheet) once active triggers #Value! as output of the function in my cell. Can someone help me? thanks
VBA Code:
Function Paragraph31()
'this code finds the column and
Application.ScreenUpdating = False
Dim FilePath As String, FilePathPrelim As String, FileName, ExcelWorksheet As String
IWP = "IWP-4210-18-1100-050"
With CreateObject("Scripting.FileSystemObject")
FilePath = .GetParentFolderName(Application.ActiveWorkbook.Path) & "/Spreadsheets/" & IWP & "/"
End With
'
PartialFilename = "Detailing*"
Dim ws As Worksheet
Dim ExcelTable As TableObject
ExcelWorksheet = "Hairpin"
'
Dim src As Excel.Workbook
FileName = Dir(FilePath & PartialFilename)
Set src = Workbooks.Open(FilePathPrelim & FileName, True, True)
Set ws = src.Worksheets(ExcelWorksheet)
'Paragraph = "ok"
Dim output As String
ComparisonVariable = (src.Worksheets(ExcelWorksheet).Range("M1").Value)
If ComparisonVariable = 1 Then
'output = "YES"
output = 1
Else
'output = "NO "
output = 2
End If
src.Close
output2 = CStr(output)
'Paragraph31 = output2
'Paragraph31 = "test"
Application.ScreenUpdating = True
Paragraph31 = output2
'Paragraph31 = 2
End Function