Concatenate Variables in VBA

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

Is there a way to return concatenated variables from a VBA UDF?

Best I can see is that you can return concatenated strings, but I don't see
a way to return concatenated variables.

I suppose I could change the variable to a string using the Str function,
but I need to convert back to do subsequent math operations.

Don
 
Don said:
Is there a way to return concatenated variables from a VBA UDF?
Best I can see is that you can return concatenated strings,
but I don't see a way to return concatenated variables.

Post what you have tried, show its result, and explain the result you are
looking form.

The straight-forward thing works for me. Here are some examples:

function cat1(a, b)
cat1 = a & b
end function

function cat2(a, b)
dim x as double, y as double
x = a: y = b
cat2 = x & y
end function

function cat3(a, b)
cat3 = --(a & b)
end function

If A1 and A2 contain the __numbers__ 1234 and 5678, =CAT1(A1,A2) returns the
__text__ "12345678". Likewise for =CAT2(A1,A2). =CAT3(A1,A2) returns a
number; of course, that works only if the concatenated string is a valid
numeric form. Beware of numbers with decimal fractions.


----- original message -----
 
Joe,

Thanks, that's exactly what I wanted.

It's also exactly how I would have expected it to work. However,yesterday
when I tried "cat2 = x & y" it didn't work. Today after reading your reply I
tried it again and it worked perfectly.

Obviously, I screwed up something yesterday.

Thanks again,
Don
 
Back
Top