|
-
Mar 15th, 2010, 07:55 PM
#1
Thread Starter
New Member
[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
-
Mar 16th, 2010, 03:42 AM
#2
Re: vb code to not run a macro if some cells are blank
assuming this is in excel
vb Code:
if isempty(range("c9")) or isempty(range("c10")) then exit sub for each c in range("h20:h200") if isempty(c) then exit sub next
this does not check for valid entries
you could change the first line to
vb Code:
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
-
Mar 16th, 2010, 05:13 AM
#3
Thread Starter
New Member
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
-
Mar 16th, 2010, 05:35 AM
#4
Re: vb code to not run a macro if some cells are blank
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
-
Mar 16th, 2010, 06:18 AM
#5
Re: vb code to not run a macro if some cells are blank
Excel VBA question moved to Office Development
-
Mar 16th, 2010, 07:22 AM
#6
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|