-
Nov 14th, 2014, 03:17 PM
#1
Thread Starter
Lively Member
-
Nov 14th, 2014, 03:35 PM
#2
Re: Excel VBA: UDF Not Working; Please Explain?
you finish by assigning an empty variant to your function
your sht variable is never set to a worksheet object
neither of which are required
try like
Code:
Public Function change2F(r as range) As Variant
change2F = (r - 32) * 9/5
End Function
though from your description the function should be change2C
for this application, you do not really require a UDF
=(a1 - 32) *9/5
directly in the cell would work
Last edited by westconn1; Nov 14th, 2014 at 03:40 PM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 14th, 2014, 04:17 PM
#3
Thread Starter
Lively Member
Re: Excel VBA: UDF Not Working; Please Explain?
WestConn1,
You are correct, I needed the change the desciption to "Change2C". I did try your code, but I received answers which were different from the In Cell references.
Here's a screenshot:
Also, just so I'm learning correctly:
your sht variable is never set to a worksheet object
If I changed the line in my original code from:
Code:
Dim sht As Worksheet ...
'changed to
Dim sht as ActiveWorksheet ...
would that be setting the variable to a worksheet object?
Last edited by IGPOD; Nov 14th, 2014 at 04:18 PM.
Reason: finish question
-
Nov 14th, 2014, 05:22 PM
#4
Re: Excel VBA: UDF Not Working; Please Explain?
Code:
change2C = (r - 32) * 9/5
should be
Code:
change2C = (r - 32) * 5/9
-
Nov 15th, 2014, 12:40 AM
#5
Re: Excel VBA: UDF Not Working; Please Explain?
would that be setting the variable to a worksheet object?
that is the declaration (or dimension of the variable), not assigning an object to the variable, which you were not doing
Code:
set sht = activesheet
Last edited by westconn1; Nov 15th, 2014 at 01:40 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|