Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Henry Evans   on Sep 02 In MS Office Category.

  
Question Answered By: Cais Nguyen   on Sep 02

You write:
"I expect the function  is being called twice."

You were right on this! The function was really called twice!
I have corrected that and it works!

But your other comments make me curious.

1. You write:
"I do see that you have defined your routine as a function, rather than
a
sub, but you are not returning a value."

The context:
The person enters a date, let's say in cell C37, that is not allowed to
be later then the cell named Today that (as you could expect) contains
"=today()". So in the spreadsheet cell C38, I write:

=AlerteDate(C37,Today)

If I had written my function as a sub, let's say sub(AlerteDate(Jour,
Aujourdhui), I guess I could not written:
= sub AlerteDate(Jour, Aujourdhui).
I don't think (that would be great in some circumstances) that I could
write in a cell "=sub macroname(Jour, Aujourdhui)".
Could I?
....................

2. You write:
Please declare your variables and parameters as specific types.

In this specific case, the function works  as well without any dim
statement.
I copied that from an example in the VB HELP provided with Excel.

But let's assume I would have needed Dim statements, I should have
written
Dim Jour As Date
Dim Aujourdhui As Date
Dim Msg As String
Dim Title As String
but
Dim style  as ... What? as vbOKOnly?


I would have so many other questions.
I have learned so many programming languages, only one in a official
course (Pascal where I can see similarities, but it's so long ago).
Many others (I started with the "Basic" of Commodore Vic 20, the
Commodore 64!) simply from the users' manual, or from books, (HTML,
Javascript - this was before Internet was so well documented and there
was no Google yet [:(] . )

I wrote also wrote many PERL scripts by just copying and adapting from
other scripts.
But with VB, it's not as easy.
I guess now I should really buy a book!

Just another little question:

Can I call a sub from a function?
Assuming I send a MsgBox of the vbYesNo style?
I know I can do it when the MsgBox is in a sub, but this brings me back
to my earlier question:
Can I call a sub from a cell?
Until now, all my sub are running when the user  clicks on a button to
which I have assigned a macro name.
Is there another way to start a macro in the case the user enters
something in a cell.
For example, I would like to be able to write:
If (B4 = somevalue, macroname)

Sorry for that long reply full of questions.

I thank you again, and I'm sorry to have used your knowledge for
something so stupid I had done!

Share: 

 

This Question has 4 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Message Box opens twice Or get search suggestion and latest updates.


Tagged: