#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 391
Default Userform

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

-----Original Message-----
Hello from Steved

Question can a userform be built so it can run a query

Example the query would be to find in Column A1

Riccarton
(Column A29), and in Row 1A Hornby (Row 1G). The result
would be that it would end up with the answer in G29 ie
15.6 Kilometres

Thanks in Advance
.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Userform

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


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

-----Original Message-----
Hello from Steved

Question can a userform be built so it can run a query

Example the query would be to find in Column A1

Riccarton
(Column A29), and in Row 1A Hornby (Row 1G). The result
would be that it would end up with the answer in G29 ie
15.6 Kilometres

Thanks in Advance
.

.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Userform Add hazel Excel Discussion (Misc queries) 8 November 3rd 06 07:01 PM
UserForm Help Jennifer Excel Discussion (Misc queries) 1 April 6th 05 10:57 AM
userform jim apostolidis Excel Programming 1 August 11th 03 10:37 AM
Userform John Wilson Excel Programming 2 August 1st 03 06:33 PM
Userform RboinD Excel Programming 1 August 1st 03 02:42 PM


All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"