Return a String from a Function

rmweaver81

New Member
Joined
Feb 4, 2013
Messages
15
Code:
Sub TrackChanges()
    Dim editWord As String


    editWord = GetWord()


End Sub


Function GetWord() As String


    Dim wordStr As String


    wordStr = "What am I doing wrong?"


End Function
In VB.Net, functions are used to process something and return some value. You actually have to type the word "Return". Apparently, this is not the case with VBA. When I run the following code, the value of editWord is "", when I would expect it to be "What am I doing wrong?", which begs the question, what am I doing wrong? Any help would be greatly appreciated!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Welcome to the baord...

Try

Rich (BB code):
Sub TrackChanges()
    Dim editWord As String

    editWord = GetWord()

End Sub

Function GetWord() As String
 
    GetWord = "What am I doing wrong?"

End Function
 
Upvote 0

Forum statistics

Threads
1,216,116
Messages
6,128,931
Members
449,480
Latest member
yesitisasport

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