Using User Define Formula in a Formula gives #Value! error

daneyuleb

New Member
Joined
Dec 8, 2021
Messages
9
Office Version
  1. 365
Platform
  1. Windows
The below function works fine when called from a command button. But, if used a cell's formula: =ShowValues("name")
the cell shows the dreaded #Value! error.

I can't figure out what's wrong--what in the function is causing it not to work as a formula?

The function simply takes some text data held in a Global Variable (the data is an array containing individual lines from a text file) - and searches for a certain text label -- and returns it if it finds it.

Am I missing something obvious--Is this just the kind of thing you just can't do in a formula?



VBA Code:
Function ShowValues(ByVal label As Variant) As Variant
   
    Dim count As Integer
    Dim Found_it As Integer
    Dim Value As String
    ' Go through each line in our split data
    For x = LBound(Split_Data_Global) To UBound(Split_Data_Global)
        If Len(Trim(Split_Data_Global(count))) <> 0 Then
            ' Non-empty line--check for our value (label)
            Found_it = InStr(1, Split_Data_Global(count), label, vbBinaryCompare)
            If Found_it Then
                ' Return the 2nd part of the split (everything after the colon)
                ShowValues = Split(Split_Data_Global(count), ":")(1)
                Exit Function
            End If
        End If
        ' Increment our line counter
        count = count + 1
        ' Next line
    Next x
End Function
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Never mind!!!

I removed the global references and that seemed to fix it!
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top