VBA output in a different cell

kokopelli

New Member
Joined
Oct 6, 2009
Messages
2
I have a function and I want it to output one word in the current cell and one in the cell to the right (i.e., the next column). Is there a way to write this in VB?

So, something along these lines (though this doesn't work):

Function test(word1 As String, word2 As String)
test = word1
test.Offset(0, 1) = word2
End Function

I suppose the general version of my question is how can I output an item in a cell other than the one the function is called from?

Thanks!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
You have the context right but you are using test. instead of ActiveCell. Change those and you should be good to go.
 
Upvote 0
Well I think the general version of the answer to your question is you can't.:)
 
Upvote 0
Thanks guys for your quick responses, but this just returns 0 when I call =test3("a","b")

Function test3(word1 As String, word2 As String)
ActiveCell = word1
ActiveCell.Offset(0, 1) = word2
End Function

Any other suggestions? Norie - is this really impossible? It seems like a pretty obvious functionality.
 
Upvote 0
Theoretically I suppose it's not impossible.

But user defined functions (UDFs) aren't really designed to alter values on a worksheet, their main purpose is to return a value.

And that value is returned to the cell the UDF is in, not another cell.:)
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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