Results 1 to 6 of 6

Thread: [RESOLVED] vb code to not run a macro if some cells are blank

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    Resolved [RESOLVED] vb code to not run a macro if some cells are blank

    Hi
    in C9 user enters a customer number e.g. 124578

    then in C10 user enters a date 16/3/2010

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

    and runs a macro

    when this happens the macro fails.

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

    Can you please advise asap ... if possible.
    Many thanks

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

    Re: vb code to not run a macro if some cells are blank

    assuming this is in excel

    vb Code:
    1. if isempty(range("c9")) or isempty(range("c10")) then exit sub
    2. for each c in range("h20:h200")
    3.   if isempty(c) then exit sub
    4. next
    this does not check for valid entries
    you could change the first line to
    vb Code:
    1. if not isdate(range("c10")) or not isnumeric(range("c9")) then exit sub
    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 to not run a macro if some cells are blank

    Hi,
    Many thanks for sending the code so soon. I am very new to VB and learning by myself. can u please send me the full code including the dim variables.
    thanks again
    regards

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

    Re: vb code to not run a macro if some cells are blank

    dim c as range
    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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: vb code to not run a macro if some cells are blank

    Excel VBA question moved to Office Development

  6. #6

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    6

    Resolved Re: vb code to not run a macro if some cells are blank

    Thanks a lot Pete, i managed to tweak it and it worked.
    Cheers
    Last edited by fnb10; Mar 16th, 2010 at 07:59 AM.

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