+ Reply to Thread
Results 1 to 6 of 6

Calling a Subroutine, Function, several if statements

  1. #1
    Registered User
    Join Date
    11-28-2006
    Posts
    63

    Question Calling a Subroutine, Function, several if statements

    Hi,

    I have some VBA code that I'm working on, and I'm not sure how to proceed. First of all, can I enbed one if statement inside another? If I can it would solve my problem.

    This is basically what I'm going for:

    Please Login or Register  to view this content.
    I'm not sure if that will work. I was thinking I may need a subroutine, or a function. The results of "do this" and "do that" will be required further in my code. If I do need a subroutine or a function, which one, and where does it go, in the main code, or in a module?

    Help
    Soma

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Calling a Subroutine, Function, several if statements

    Yes, embedding multiple if statements within one another as you have described is fine, you may also want to look at Select Case.

    It's not a good idea to jump around within a procedure unless you really have to so as you suggest this and that could be separate procedures which you can Call:

    You would just use

    Please Login or Register  to view this content.
    One MyProcedureName (or whatever your sub is called) has executed it will return to the point it was called from and continue unless you have told it otherwise.

    Dom
    Last edited by Domski; 02-10-2010 at 11:51 AM.
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    11-28-2006
    Posts
    63

    Re: Calling a Subroutine, Function, several if statements

    Thanks, but where would I write the code for this MyProcedure? Is it in with the main code, or in it's own module?

    Soma

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Calling a Subroutine, Function, several if statements

    It can be in the same module or in another one if it makes more sense, no matter really.

    Something like this as an example:

    Please Login or Register  to view this content.
    Dom

  5. #5
    Registered User
    Join Date
    11-28-2006
    Posts
    63

    Re: Calling a Subroutine, Function, several if statements

    Thanks Dom,

    I will give it a try. You've been a great help.

    Soma

  6. #6
    Registered User
    Join Date
    11-28-2006
    Posts
    63

    Re: Calling a Subroutine, Function, several if statements

    It didn't work, I'm sure I'm doing something wrong, but not sure what. This is currently what I have

    Please Login or Register  to view this content.


    There's a little more to it than this. The problem is that the msgbox is coming up empty, and the color data is not being written to the worksheet.

    I'm stumped.

    Soma

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1