rjplante
Well-known Member
- Joined
- Oct 31, 2008
- Messages
- 574
- Office Version
- 365
- Platform
- Windows
I have a long macro which I have summarized below and I am trying to understand why the 'Compile VBAProject' tool flags the 'END IF' statements near then end of my macro code. From my understanding, you need to close your 'IF' statements with and 'END IF' statement. I have written this summary so that I could track my IF/THEN/END IF statements in my macro. I would appreciate it if anyone could look this over and tell me why the last two 'END IF' statements with an '*' in front of them appear to be unnecessary, as they lead to flags when I run the Compile VBAProject tool.
I am a novice with the VBA programming and I am trying to learn as fast as I can. I appreciate all the support found here.
Thanks to all of you power programmers,
Robert
=================================
SUB CONICAL_UPDATE
IF case #1 (open IF #1)
Code section - MsgBox ‘YES – NO’
IF answer is ‘NO’ (open if #2)
Code section - Amend data table
IF data is from Form #1 – case #1 (open IF #3)
Code section
ELSE IF data is from Form #2 – case #2 (continuation of IF #3)
Code section
EXIT SUB
END IF data from case 1 & 2 has been dealt with (close IF#3)
ELSE IF answer is ‘YES’ (continuation of IF #2)
Code section – Transfer and overwrite data table
IF replacement data comes from Form #1 (open IF #4)
Code section
ELSE IF replacement data comes from Form #2 (Continuation of IF#4)
Code section
*END IF replacement data dealt with (Close of IF #4)
**END IF ‘YES’ and ‘NO’ cases dealt with (close of IF #2)
ELSE what to do if case#1 is FALSE (continuation of IF #1)
Code section
END IF ‘TRUE’ and ‘FALSE’ cases dealt with (close of IF #1)
END SUB
*When just this ‘End IF’ statement is here results in a “Compile error: ELSE without IF” statement.
**When both ‘END IF’ statements are here this results in a “Compile error: End IF without block IF” statement.
Removal of both of the above ‘END IF’ statements results in no compile errors when running the code “Compile VBA Project” tool.
=================================
I am a novice with the VBA programming and I am trying to learn as fast as I can. I appreciate all the support found here.
Thanks to all of you power programmers,
Robert
=================================
SUB CONICAL_UPDATE
IF case #1 (open IF #1)
Code section - MsgBox ‘YES – NO’
IF answer is ‘NO’ (open if #2)
Code section - Amend data table
IF data is from Form #1 – case #1 (open IF #3)
Code section
ELSE IF data is from Form #2 – case #2 (continuation of IF #3)
Code section
EXIT SUB
END IF data from case 1 & 2 has been dealt with (close IF#3)
ELSE IF answer is ‘YES’ (continuation of IF #2)
Code section – Transfer and overwrite data table
IF replacement data comes from Form #1 (open IF #4)
Code section
ELSE IF replacement data comes from Form #2 (Continuation of IF#4)
Code section
*END IF replacement data dealt with (Close of IF #4)
**END IF ‘YES’ and ‘NO’ cases dealt with (close of IF #2)
ELSE what to do if case#1 is FALSE (continuation of IF #1)
Code section
END IF ‘TRUE’ and ‘FALSE’ cases dealt with (close of IF #1)
END SUB
*When just this ‘End IF’ statement is here results in a “Compile error: ELSE without IF” statement.
**When both ‘END IF’ statements are here this results in a “Compile error: End IF without block IF” statement.
Removal of both of the above ‘END IF’ statements results in no compile errors when running the code “Compile VBA Project” tool.
=================================