alt= data-orig-width=395 data-orig-height=277 data-ezsrc=http://31.220.61.170/wp-content/uploads/2020/11/How-to-Fix-the-End-If-without-block-If-Error.png data-ez= />

alt=Plug in! data-ezsrc=/utilcave_com/social/pin_it.png />

alt=Change to Facebook data-ezsrc=/utilcave_com/social/fb_share.png />

Today I’m going to show you how to correct an End If without Block If error in VBA. But you have to understand the explanation first if you want to solve the problem.

Statements of Assumptions and their various forms

The if-operator is a condition that helps us execute the code using a condition that is resolved at runtime. You may ask yourself one question: What is the need to make a status decision at the time of implementation? Can’t we solve this problem first? In reality, there are many situations in which action should only be taken if certain criteria or conditions are met. Sometimes this check even depends on the input value of the user.

Imagine, for example, that the bank offers a return of 8% for term accounts when the customer is retired and only 6% for other customers. In this case, the code that calculates the interest amount and the due date must both (a) take into account the age of the client and (b) use a condition that makes it possible to use different values for older and other students. In this case, the message appears when the condition operator is triggered.

Now let’s look at the code for the above scenario, which assumes that a person has to be 60 years old to be considered a retired person.

Sub sample_coding()
‘Declaration of variables
Dim matamt, prinamt, king, term, custard
get user input
custard = InputBox(Enter age of customer)
assign values
prinamt = 10000 principal
term = 2 2 years
solve, King value
If Custard < 60 then
King = 6
Else
King = 8
End If
is the formula for calculating the FD-runtime.
matamt = print + (prinamt * king * term / 100)
‘ Print output
Debug.matamt print
End Sub

If we look at the above example, we can see that the syntax for the use of the simple operator is equal to

If then

End If

But one and the same conditional operator has different forms, which are listed below.

  1. Simple as a block
  2. Yew tree block – Elsa
  3. Elsen-Ife Block
  4. Nested as a unit

Compilation error Output if unlocked if :

This is a simple compilation error that occurs when code with If blocks does not match the syntax (or) of this declaration.

Here are a few cases where such an error can occur

Rule 1: End of line box with one operator

If a line code to be executed is on the same line as the if-operator, the end of the if-operator must be omitted. In other words, the If operator is considered complete without the Complete If operator when the condition code is placed on a line.

If the condition is correct, then the code is correct.

For example:

The if condition in this code can be rewritten with this line to prevent the compilation error End If without Block If.

correct king usually
king = 8
‘ change value for non-students only with line 1
as custard < 60 dan king = 6
‘ note or delete end as statement to correct error.
The end is when

According to rule 1, if End If is used in the above code, an End If error will occur without Block If. So don’t forget to put it away.

If you are using a nested option, make sure that each opened As operator has the correct end of the As operator. This is in addition to rule 1 above.

Example 1

If Custard < 60 then
roi = 6
If Custard = female and Custard > 57 then roi = 8
End If ‘********Line explained below*********
Elsa
roi = 8
End If

It’s a piece of code,

  • Internal If the condition follows line 1 (i.e. the keyword in the same expression is fixed in the code). This statement is therefore a self-contained statement that does not need to be completed as.
  • But because we have the end as operator, we believe that it corresponds to the end of the external as operator (rule 1).
  • The result is a search for the keyword Si in the fifth line. In exchange we get the Else error without If, which is similar to the End If error without Block If.
  • The solution to this problem is to eliminate the useless end when the 4th step is completed. or to move the code king=8 to the next line, i.e. between IF… and End if declarations.

Example 2

If apple = sweet, then
If mango = sweet, then Debug.print Sweet fruit
fine Si
fine Si

In this example,

  • Since line 2 here is already filled without the last cases, line 3 is automatically assigned to the If operator of line 1.
  • So End Si looks for his pair of Si on the fourth line and causes a compilation error End Si without Block Si.
  • The solution to this problem is to remove line 3 or put the Debug.print statement on a separate line for the End If statement on line 3.

Rule 3: Forgot part of the remote control code

Make sure it is not filled in if the request is in your code without If the request is in your code. This can happen if you keep the code or change the logic after a long time.

For example, you might think that you don’t need a block of code when – end, when at some point. And once you have removed the if block operator, you can forget about removing the if operator. This in turn leads to the same compilation error we see all the time: Finish Si without Si block.

For example:

If apple = sweet, then
ends, if
ends, if

Imagine that you want to remove the internal as a block in the example above. At the same time, you forgot to remove the End-If operator. You will certainly encounter the compilation error End If without Block If.

Here is a video that explains everything described above with example codes.  The code is explained and executed line by line so that you can clearly understand the cause of the block-free end in the event of an error.

Summary

In principle, when looking at an error message, it becomes clear that it will be rejected if there are unnecessary final statements. The only solution is to follow the code and delete the erroneous declaration after it has been confirmed that it does not affect the rest of the code.

Another Else without If compilation error, an example of which is given in line 2, relates to this error. Throw if there’s another statement or just another statement without another statement if there’s another statement. In general, it is wise and quick to check the syntax for each error and then start troubleshooting.