End if without Block if followed by Block if without End if !

nmounir

Board Regular
Joined
Oct 16, 2020
Messages
107
Office Version
  1. 365
Platform
  1. Windows
Good day,

I am trying to write this code but i keep getting this error all the time.

any idea how to fix this?

Thank you
 

Attachments

  • end if without block if.PNG
    end if without block if.PNG
    21.7 KB · Views: 39
  • End if without block if 2.PNG
    End if without block if 2.PNG
    21.4 KB · Views: 40

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
It's always best to post all the code here and not a image of the code.
 
Upvote 0
You should only have one End If & it should go after the Next CD line
 
Upvote 0
Solution
I put End If after the Next CD line and i am still getting the same error.
I also tried to write code as an array to make the sheet faster since it is already very slow but it is not working.
Basically what i am trying to do is if i choose a certain date in some other cell (say L44), the table would contract (using formula) and i would like to the percentage in the third row (which hard coded) to become zero as per image 2 and 3
 

Attachments

  • Capture.PNG
    Capture.PNG
    31.7 KB · Views: 11
  • Table 1.PNG
    Table 1.PNG
    6.7 KB · Views: 11
  • Table 2.PNG
    Table 2.PNG
    4.4 KB · Views: 11
Upvote 0
The "End If" needs to come before the "Next CD".
 
Upvote 0
I apologise i posted a wrong code in my second post. i tried to put the end if before and after and both methods didn't work !!!
as could see the 2% in column 3 in the table didn't change to 0

Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRenewedCDs As Range
Dim CD As Range
Application.EnableEvents = False

Set MyRenewedCDs = Range("J47:J71")
If Not Intersect(Target, MyRenewedCDs) Is Nothing Then
For Each CD In MyRenewedCDs
If CD.Value = "" Then CD.Offset(0, 2).Value = 0
End If
Next CD

Application.EnableEvents = True

End Sub
 

Attachments

  • Table 3.PNG
    Table 3.PNG
    33.7 KB · Views: 7
  • Table 4.PNG
    Table 4.PNG
    4.8 KB · Views: 7
Upvote 0
I put End If after the Next CD line and i am still getting the same error.
That's because that code is totally different from the code you originally posted.
 
Upvote 0
As I said before it must go after the Next Cd line
 
Upvote 0
I apologise i posted a wrong code in my second post. i tried to put the end if before and after and both methods didn't work !!!
as could see the 2% in column 3 in the table didn't change to 0

Private Sub Worksheet_Change(ByVal Target As Range)
Dim MyRenewedCDs As Range
Dim CD As Range
Application.EnableEvents = False

Set MyRenewedCDs = Range("J47:J71")
If Not Intersect(Target, MyRenewedCDs) Is Nothing Then
For Each CD In MyRenewedCDs
If CD.Value = "" Then CD.Offset(0, 2).Value = 0
End If
Next CD

Application.EnableEvents = True

End Sub
 

Attachments

  • Table 3.PNG
    Table 3.PNG
    33.7 KB · Views: 4
  • Table 4.PNG
    Table 4.PNG
    4.8 KB · Views: 4
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top