VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 300,513 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,944 people online right now. Registration is fast and FREE... Join Now!




Getting the results of a function into a messagebox...

 

Getting the results of a function into a messagebox...

Blackeye

26 Sep, 2008 - 04:03 PM
Post #1

New D.I.C Head
*

Joined: 27 Nov, 2007
Posts: 3


My Contributions
I have been trying to figure out how to get the results of a function in a messagebox... the function seems to be working...but getting the results in the message box is stumpping me...

User is offlineProfile CardPM
+Quote Post


thava

RE: Getting The Results Of A Function Into A Messagebox...

26 Sep, 2008 - 04:12 PM
Post #2

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 894



Thanked: 51 times
Dream Kudos: 75
My Contributions
show what is your coding and if i can i will found it or else some one of us will clear your problem
User is offlineProfile CardPM
+Quote Post

jaakko

RE: Getting The Results Of A Function Into A Messagebox...

26 Sep, 2008 - 04:23 PM
Post #3

New D.I.C Head
*

Joined: 26 Sep, 2008
Posts: 21



Thanked: 6 times
My Contributions
QUOTE(Blackeye @ 26 Sep, 2008 - 05:03 PM) *

I have been trying to figure out how to get the results of a function in a messagebox... the function seems to be working...but getting the results in the message box is stumpping me...


msgbox(modelfunction())

function modelfunction()
modelfunction = "ABCDE"
end function

or

ab = modelfunction()

msgbox(ab)

greetings jaakko
User is offlineProfile CardPM
+Quote Post

Blackeye

RE: Getting The Results Of A Function Into A Messagebox...

26 Sep, 2008 - 05:14 PM
Post #4

New D.I.C Head
*

Joined: 27 Nov, 2007
Posts: 3


My Contributions
Here is my code... I am a novice...cannot figure out how to get the results into a message box... I get "Type Mismatch"

vb

Option Explicit
Sub Test()
Dim ws As Worksheet

Workbooks.Open Filename:= _
"C:\Documents and Settings\Blake B. Nelson\Desktop\IT Development\Pricer.xls"

MsgBox "The Active sheet is :" & ActiveSheet.Name
MsgBox "The Used Range of this Worksheet is: " & GetUsedRange(ActiveSheet)

End Sub
Public Function GetUsedRange(ws As Worksheet) As Range

' Assumes that Excel's UsedRange gives a superset
' of the real used range.

Dim s As String, x As Integer
Dim rng As Range
Dim r1Fixed As Integer, c1Fixed As Integer
Dim r2Fixed As Integer, c2Fixed As Integer
Dim i As Integer
Dim r1 As Integer, c1 As Integer
Dim r2 As Integer, c2 As Integer

Set GetUsedRange = Nothing

' Start with Excel's used range
Set rng = ws.UsedRange

' Get bounding cells for Excel's used range
' That is, Cells(r1,c1) to Cells(r2,c2)
r1 = rng.Row
r2 = rng.Rows.Count + r1 - 1
c1 = rng.Column
c2 = rng.Columns.Count + c1 - 1

' Save existing values
r1Fixed = r1
c1Fixed = c1
r2Fixed = r2
c2Fixed = c2

' Check rows from top down for all blanks.
' If found, shrink rows.
For i = 1 To r2Fixed - r1Fixed + 1
If Application.CountA(rng.Rows(i)) = 0 Then
' empty row -- reduce
r1 = r1 + 1
Else
' nonempty row, get out
Exit For
End If
Next

' Repeat for columns from left to right
For i = 1 To c2Fixed - c1Fixed + 1
If Application.CountA(rng.Columns(i)) = 0 Then
c1 = c1 + 1
Else
Exit For
End If
Next

' Reset the range
Set rng = _
ws.Range(ws.Cells(r1, c1), ws.Cells(r2, c2))

' Start again
r1Fixed = r1
c1Fixed = c1
r2Fixed = r2
c2Fixed = c2

' Do rows from bottom up
For i = r2Fixed - r1Fixed + 1 To 1 Step -1
If Application.CountA(rng.Rows(i)) = 0 Then
r2 = r2 - 1
Else
Exit For
End If
Next

' Repeat for columns from right to left
For i = c2Fixed - c1Fixed + 1 To 1 Step -1
If Application.CountA(rng.Columns(i)) = 0 Then
c2 = c2 - 1
Else
Exit For
End If
Next

Set GetUsedRange = _
ws.Range(ws.Cells(r1, c1), ws.Cells(r2, c2))

End Function


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM
+Quote Post

akhileshbc

RE: Getting The Results Of A Function Into A Messagebox...

27 Sep, 2008 - 12:02 AM
Post #5

D.I.C Head
Group Icon

Joined: 26 Sep, 2008
Posts: 177



Thanked: 6 times
Dream Kudos: 50
My Contributions
Are you using the vbscript(macro) in excel for this???
Which line shows that error???

User is offlineProfile CardPM
+Quote Post

thava

RE: Getting The Results Of A Function Into A Messagebox...

27 Sep, 2008 - 02:25 AM
Post #6

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 894



Thanked: 51 times
Dream Kudos: 75
My Contributions
since msgboxes are always use to display the string it shows the error
try this line
CODE

    MsgBox "The Used Range of this Worksheet is: " & CStr(GetUsedRange(ActiveSheet).Address)

this will display the address of used range i think this is what you need
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 05:15AM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month