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
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