using 2 different IF statements

T

Tonso

I have a macro that, after the user fills in 2 different areas of a
form, the data in those areas are appended to an Excel list. If either
area is not completely filled out, I want a message to appear
indicating where the problem is, and the sub exited. I used the
following code:
If Range("c3") = "" Or Range("c4") = "" Or Range("C5") = "" Or
Range("C6") = "" Or _
Range("C7") = "" Or Range("C8") = "" Then
answer = MsgBox("Incomplete Header Information", vbInformation)
End If
If Range("j10") = "" Or Range("j11") = "" Or Range("j12") = "" Or
Range("J13") = "" Or _
Range("J14") = "" Or Range("J15") = "" Or Range("J16") = "" Or
Range("J17") = "" Or _
Range("J18") = "" Or Range("J19") = "" Or Range("J20") = "" Or
Range("J21") = "" Then
answer = MsgBox("All Questions must be answered Yes/No",
vbInformation)
Else
Application.ScreenUpdating = False
Range("c3:c8").Select
Selection.Copy
etc etc etc
End If
End Sub

If the area C3:C8 is incomplete, and J10:J21 is complete, the 1st
message appears, as it should, but the sub is ran instead of exited.
Otherwise, it works as it should. How do I correct this. I am pretty
certain this is probably not the most efficient way to accomplish
this.

Thanks,

Tonso
 
I

isabelle

hi Tonso,

If Application.CountA(Range("c3:c8")) = 6 Then a = 1 Else a = 0
If Application.CountA(Range("j10:J21")) = 12 Then b = 1 Else b = 0
r = "" & a & b

Select Case r
Case "01": MsgBox "Incomplete Header Information", vbInformation
Case "00": MsgBox "All Questions must be answered Yes/No", vbInformation
'you can add another case "10"
End Select


--
isabelle



Le 2012-01-05 09:15, Tonso a écrit :
 
T

Tonso

hi Tonso,

If Application.CountA(Range("c3:c8")) = 6 Then a = 1 Else a = 0
If Application.CountA(Range("j10:J21")) = 12 Then b = 1 Else b = 0
r = "" & a & b

Select Case r
  Case "01": MsgBox "Incomplete Header Information", vbInformation
  Case "00": MsgBox "All Questions must be answered Yes/No", vbInformation
  'you can add another case "10"
End Select

--
isabelle

Le 2012-01-05 09:15, Tonso a écrit :





- Show quoted text -

Thank you so much Isabelle!

Tonso
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top