Thanks Don & Chip,
Your posts answered some other questions I had and gave me some formating
guidance, however, my particular question (perhaps not phrased properly) was
can an "If ... Then" sequence handle more that a single line of code per
result.
Back in the old days, before
VB, we used a GOSUB ... RETURN sequence that
would run a multi-line block of code and RETURN to the next line in sequence
once completed, e.g.
IF var = True THEN GOSUB SubRoutine1
SubRoutine1:
1 Line of code
2 Line of code
3 Lines of code
RETURN
In the above case, if the var = False the GOSUB would be ignored and the
next line of code following the IF...THEN line would be executed. My
question is simply this: Using the above example, how do I get code lines
1-3 to execute only if var= True. Do I simply create a separate macro
subroutine and use this format?
IF var = True THEN RUN("MacroSubRoutine1")
Since the VBA indentation format in the If block does not seem to work for
multiple lines.
Thanks for all of your help.
--
Brian
"Don Guillett" wrote:
Your problem was a continuation after the first then _
I would write it like this
With ActiveSheet' you could substitute the sheet name & NOT select
If .Range("i6") = "HCP Added" Then
.Unprotect
.Range("I6").ClearContents
.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True, AllowInsertingHyperlinks:=True
End If
Calculate
With Sheets("Data Entry")
If .Visible = True Then .Visible = False
End With
With Sheets("Main Menu")
If .Visible = True Then Application.Goto .Range("F4:H4")
End With
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
"Brian" wrote in message
...
Hello All,
Is there some way in Excel 2007 VBA macro code to have a block of code
perform if a condition is true and have the code block skipped if the
condition is false? So far I have only been able to get an If...Then
condition to work with a single line of code following the Then statement.
Do I use GoSub...Return?
See the following code:
Range("I6").Select
If ActiveCell.FormulaR1C1 = "HCP Added" Then _
ActiveSheet.Unprotect
Range("I6").Select
Selection.ClearContents
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, _
Scenarios:=True, AllowInsertingHyperlinks:=True
End If
Calculate
If Sheets("Data Entry").Visible = True Then
Sheets("Data Entry").Select
ActiveWindow.SelectedSheets.Visible = False
End If
If Sheets("Main Menu").Visible = True Then
Sheets("Main Menu").Select
Range("F4:H4").Select
End If
End Sub
Can you assist and tell me what I am doing wrong?
--
Brian