Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default How to paste values in a spreadsheet with a VBA function

Hi, I want to know how to use the instruction Range("RangeName").Value
= Output in a VBA function to paste in a spreadsheet a value which is
not the principal output of the function.

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default How to paste values in a spreadsheet with a VBA function

You need to passback the output to the function. Refer the example below
Getword accepts two arguments and return a string. Note the last line in the
code where the output is assigned back to the function name.

A1 = "This is a test"
B1 = GetWord(A1,3)

Function GetWord(strTemp As String, lngPos As Long) as String
'Function to return the nth word from a text string..from a cell
If InStr(Trim(strTemp), " ") = 0 Then Exit Function
lngPos = lngPos - 1
arrTemp = Split(Trim(strTemp), " ")
If lngPos UBound(arrTemp) Or lngPos < 0 Then Exit Function
GetWord = arrTemp(lngPos)
End Function


--
If this post helps click Yes
---------------
Jacob Skaria


" wrote:

Hi, I want to know how to use the instruction Range("RangeName").Value
= Output in a VBA function to paste in a spreadsheet a value which is
not the principal output of the function.

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default How to paste values in a spreadsheet with a VBA function

Thanks Jacob. The value I need to paste in a cell is not the output
of the function. I want to paste a second value that the function
computes in a cell different from the one I typed the function. Is
this possible using a VBA function?

Thanks

On May 3, 12:08*am, Jacob Skaria
wrote:
You need to passback the output to the function. Refer the example below
Getword accepts two arguments and return a string. Note the last line in the
code where the output is assigned back to the function name.

A1 = "This is a test"
B1 = GetWord(A1,3)

Function GetWord(strTemp As String, lngPos As Long) as String
'Function to return the nth word from a text string..from a cell
If InStr(Trim(strTemp), " ") = 0 Then Exit Function
lngPos = lngPos - 1
arrTemp = Split(Trim(strTemp), " ")
If lngPos UBound(arrTemp) Or lngPos < 0 Then Exit Function
GetWord = arrTemp(lngPos)
End Function

--
If this post helps click Yes
---------------
Jacob Skaria

" wrote:
Hi, I want to know how to use the instruction Range("RangeName").Value
= Output in a VBA function to paste in a spreadsheet a value which is
not the principal output of the function.


Thanks


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to paste values in a spreadsheet with a VBA function

UDF's can't stuff values into other cells. They return values to the cells that
contain the UDF call.

On the other hand, you could have a multicell array function that receives
values from the function. But that means you're entering an array formula into
that multicell range.

wrote:

Thanks Jacob. The value I need to paste in a cell is not the output
of the function. I want to paste a second value that the function
computes in a cell different from the one I typed the function. Is
this possible using a VBA function?

Thanks

On May 3, 12:08 am, Jacob Skaria
wrote:
You need to passback the output to the function. Refer the example below
Getword accepts two arguments and return a string. Note the last line in the
code where the output is assigned back to the function name.

A1 = "This is a test"
B1 = GetWord(A1,3)

Function GetWord(strTemp As String, lngPos As Long) as String
'Function to return the nth word from a text string..from a cell
If InStr(Trim(strTemp), " ") = 0 Then Exit Function
lngPos = lngPos - 1
arrTemp = Split(Trim(strTemp), " ")
If lngPos UBound(arrTemp) Or lngPos < 0 Then Exit Function
GetWord = arrTemp(lngPos)
End Function

--
If this post helps click Yes
---------------
Jacob Skaria

" wrote:
Hi, I want to know how to use the instruction Range("RangeName").Value
= Output in a VBA function to paste in a spreadsheet a value which is
not the principal output of the function.


Thanks


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default How to paste values in a spreadsheet with a VBA function

Try this. You can get the required value to a global variable within the
function...and have another function to retrieve that value..Something like
the below

A1 = "This is a test"
B1 = GetWord(A1,1)
C1 = GetWordLength()

Keep on changing the first word in A1 and see...

Insert a new module in VBE and copy the below code.


Dim intWordLength As Integer 'General Declarations
'------------------------------------
Function GetWordLength()
GetWordLength = intWordLength
Application.Volatile
End Function
'-----------------------------------------------
Function GetWord(strTemp As String, lngPos As Long) As String
'Function to return the nth word from a text string..from a cell
If InStr(Trim(strTemp), " ") = 0 Then Exit Function
lngPos = lngPos - 1
arrTemp = Split(Trim(strTemp), " ")
If lngPos UBound(arrTemp) Or lngPos < 0 Then Exit Function
intWordLength = Len(arrTemp(lngPos))
GetWord = arrTemp(lngPos)
End Function


If this post helps click Yes
---------------
Jacob Skaria


" wrote:

Thanks Jacob. The value I need to paste in a cell is not the output
of the function. I want to paste a second value that the function
computes in a cell different from the one I typed the function. Is
this possible using a VBA function?

Thanks

On May 3, 12:08 am, Jacob Skaria
wrote:
You need to passback the output to the function. Refer the example below
Getword accepts two arguments and return a string. Note the last line in the
code where the output is assigned back to the function name.

A1 = "This is a test"
B1 = GetWord(A1,3)

Function GetWord(strTemp As String, lngPos As Long) as String
'Function to return the nth word from a text string..from a cell
If InStr(Trim(strTemp), " ") = 0 Then Exit Function
lngPos = lngPos - 1
arrTemp = Split(Trim(strTemp), " ")
If lngPos UBound(arrTemp) Or lngPos < 0 Then Exit Function
GetWord = arrTemp(lngPos)
End Function

--
If this post helps click Yes
---------------
Jacob Skaria

" wrote:
Hi, I want to know how to use the instruction Range("RangeName").Value
= Output in a VBA function to paste in a spreadsheet a value which is
not the principal output of the function.


Thanks



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
find values in multiple cells and paste row values izzyt1972 Excel Discussion (Misc queries) 5 December 26th 07 10:14 PM
can you change the default paste method? (paste values) David A Brown Excel Discussion (Misc queries) 3 December 18th 07 09:59 AM
Copy and paste of a spreadsheet Cheri Excel Discussion (Misc queries) 2 June 7th 06 06:08 PM
Copy / Paste Special / Values for a whole spreadsheet ? Colin2 Excel Discussion (Misc queries) 4 May 23rd 06 05:11 PM
can I paste a shortcut to a spreadsheet? If so, How? amber2221982 Excel Discussion (Misc queries) 1 May 26th 05 07:59 PM


All times are GMT +1. The time now is 02:10 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"