Userform

  • Thread starter Thread starter Patrick Molloy
  • Start date Start date
P

Patrick Molloy

Sure, anything that you do in VBA can be done in a
userform....pretty much everything. But why use a
userform?

A simple User Defined Function will return the value

Function GetDistance(PlaceA As String, _
PlaceB As String) As Variant
Dim target As Range
Dim ResultRow As Long
Dim ResultCol As Long

' find the row of the first place
Set target = Range("A:A").Find(PlaceA)

If target Is Nothing Then

GetDistance = PlaceA & " not found."

Else
' save the row
ResultRow = target.Row
' find the second place
Set target = Range("1:1").Find(PlaceB)

If target Is Nothing Then

GetDistance = PlaceB & " not found."
Else

ResultCol = target.Column

End If
End If


If ResultRow > 0 And ResultCol > 0 Then

GetDistance = Cells(ResultRow, ResultCol)

End If

End Function
 
Hello Patrick from Steved

Thankyou

I am getting a error which is
Compile error
Ambiguous Name detected:GetDistance,
Please understand I am relatively new in VBA programing
and still finding my way round. Ok saying that This is
what I believe your function is for me to type in cell A1
Riccarton and in Cell A2 Hornby in cell A3 Run the
Function Command which Shows Riccarton I then push ok it
is at this point it greats the error. Something tells me
that I have misred something here. Please help
 
Back
Top