Results 1 to 6 of 6

Thread: vb code for macro to not execute when blank cell encountered.

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    vb code for macro to not execute when blank cell encountered.

    Hi
    in C9 user enters a customer number e.g. 124578 (mandatory must enter number)

    then in C10 user enters a date 16/3/2010 (mandatory must enter date)


    and from H20:H200 the user fails to enter required qty e.g. 2,5 or 100.

    (mandatory, user must enter quantity in atleast one cell between this range).

    and runs a macro

    when this happens the macro must fail.

    I want to stop the macro from being executed if all above 3 criterias are not fulfilled.

    Can you please advise asap
    Many thanks

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: vb code for macro to not execute when blank cell encountered.

    what is the difference between this question and your previous one?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    Re: vb code for macro to not execute when blank cell encountered.

    the difference is after i modified the code i found that i had to enter a value in all rows in the h column until 200. what i want is in that range H20 to H200 even if i enter one value in either one of the rows then that is acceptable.
    have attached a mock file with code for your reference.
    thanks again.
    Attached Files Attached Files
    Last edited by fnb10; Mar 20th, 2010 at 08:08 AM.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: vb code for macro to not execute when blank cell encountered.

    vb Code:
    1. dim notallempty as boolean, c as range
    2. for each c in range("o3:0333")
    3.   if not isempty(c) then notallempty = true: exit for
    4. next
    5. if not isempty(range("c9")) and not isempty(range("c10") and notallempty then
    6. else
    7.   exit sub
    8. end if
    change ranges to suit, i didn't test, but looks right
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    Re: vb code for macro to not execute when blank cell encountered.

    thank but it's falling off at no. 5 ( the code is appearing in red) and am trying to check why but so far cudn't figure it out.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: vb code for macro to not execute when blank cell encountered.

    needs extra closing bracket after c10"
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width