I have an Excel worksheet with some strings in a column. Sometimes all of the entries are the same, and sometimes not:

![enter image description here](https://i.stack.imgur.com/Hip6m.jpg)

![enter image description here](https://i.stack.imgur.com/7sJXA.jpg)

I wrote a function to pass the range as a parameter:

```
=Dent_WG(A1:A6)

```

The VBA function should determine which case is true (all entries = "Al", or at least one entry = "Ag"), then return 0 or 12 respectively:

```
Function DentWG(WG_Mat As Range) As Single

    Dim dat As Variant, rw As Variant, temp As Single
    dat = WG_Mat
    temp = 0

    For rw = LBound(dat, 1) To UBound(dat, 1)
        If dat(rw, 1) = "Ag" Then
            temp = 12
        End If
    Next

    If temp = 12 Then
        DentWG = 12
    Else
        DentWG = 0
    End If

End Function

```

However, the function always returns 0, even for the 2nd case where "Ag" occurs in the range. I'm sure I'm failing to correctly convert the range into an array or correctly apply the intended logic to that array.