Functions having Errors

woon8888

New Member
Joined
May 18, 2022
Messages
13
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
I'm creating a sub to call a function, but i kept having error from the below code.

VBA Code:
Sub ttimeTEST()
Dim timeA As Date
Dim locnA, locnB As String

locnA = "Singapore"
locnB = "Malaysia"

timeA = TravelTime(locnA, locnB)

Debug.Print (timeA)

End Sub

Private Function TravelTime(ByRef locnA As String, ByRef locnB As String) As Date
    Dim ttimeWS As Worksheet
    Dim TTTime As Date
    
    Set ttimeWS = ThisWorkbook.Sheets("ttime")
    
    TTTime = Intersect(ttimeWS.Columns(1).Find(locnA).EntireRow, ttimeWS.Rows(1).Find(locnB).EntireColumn).Value

End Function
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Try it like
VBA Code:
Dim locnA As String, locnB As String
Otherwise LocnA is a Variant
 
Upvote 0
thanks and it works! However, when i debug.print the results is not the same as the output from the function.
The TTTime states : 5hrs but timeA states 12:00:00 AM
 
Upvote 0
In that case can you post some data from the ttime sheet.
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0

Forum statistics

Threads
1,215,262
Messages
6,123,939
Members
449,134
Latest member
NickWBA

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