View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Chris T-M Chris T-M is offline
external usenet poster
 
Posts: 43
Default "Or" statement not working

OK you lost me. Did I mention I am new to VBA?
That being said, the logic I used in the Macro works if used as a Function,
so why wouldn't it work in a Macro (programming language asside)?

Regardless of my understanding, setting this up as an "On Error GoTo..."
does work.

As for my previous contridiction, I appologize. What I meant to say was:
If any are true, then show message.
If all are false, then do macro.

For the Macro Logic (broken out):
If Range("Q44").Value = "Fill in..." Then GoTo ShowMsgBox
If Range("F47").Value = Range("AB2").Value Then GoTo ShowMsgBox
If Range("H56").Value = Range("AH2").Value Then GoTo ShowMsgBox


The Value = Value cells are text values. Both effectively contain
instructions for what data is desired unless one of them is filled in. If one
is filled in, then I can concatelate a statement such as "The name of the new
project is" "NewProj".

Thank you for the additional advice,
Chris T-M


"Bill Renaud" wrote:

Never mind the post immediately above; it is incomplete. I should have
expanded it out to something like the following (hyphen means "don't
care"):

Q44 F47 H56 Action
-------------- ----- ----- ------
="Fill in..." - - MsgBox
- empty - MsgBox
- - empty MsgBox
- =AB2 - MsgBox
- - =AH2 MsgBox
<"Fill in..." <AB2 <AH2 Do macro

Chris T-M wrote (in another post):
<<If any of these conditions exist, then I want the message. Only if all
are met do I want to continue the macro.

This appears to be contradictory. If any conditions exist (OR), then show
the message. If all are met (AND) then do the macro. This does not make
sense to me.

As an alternative, I sometimes use a program structure like the following
(or declare ShowMsgBox to be an error handler and use Err.Raise):

'----------------------------------------------------------------------
Sub CheckCellContent()
Dim strMsgBox As String

If Range("Q44").Value = "Fill in..." Then GoTo ShowMsgBox
If IsEmpty(Range("F47")) Then GoTo ShowMsgBox
If IsEmpty(Range("H56")) Then GoTo ShowMsgBox

If OtherConditions _
Then
'Do macro.
End If

GoTo ExitSub

ShowMsgBox:
strMsgBox = "You have not filled in all" & vbNewLine & _
"fields required to generate" & vbNewLine & _
"a complete project number." & vbNewLine & _
vbNewLine & _
"Please fill in the Abbreviation," & vbNewLine & _
"Project Type, Class, and Application" & vbNewLine & _
"Date fields (blue font with an *)."

MsgBox strMsgBox, _
vbCritical + vbOKOnly, _
"Incomplete Project Number"
ExitSub:
End Sub

--
Regards,
Bill Renaud