Block If without End If

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
Morning,
Please can you check my code & advise what im missing.
Currently i get the RTE Block If without End If but i also believe there is another issue.

This works fine.
Rich (BB code):
Private Sub AprilStartButton_Click()

If WorksheetFunction.CountA(Range("B4:B13")) > 0 Then
    answer = MsgBox("CELLS CONTAIN VALUES ALREADY, OVERWRITE THEM ?", vbCritical + vbYesNo)
    If answer = vbNo Then
        Exit Sub
    End If
End If
   
Range("I9:I18").Copy Destination:=Range("B4:B13")
MsgBox "ALL FIGURES HAVE BEEN TRANSFERED", vbInformation, "MONTHS FIGUES MESSAGE"
Unload SUMMARYSHEETYEAR
Range("I9:I18").ClearContents
Range("I9").Select

End Sub

The code above doesnt take into consideration that the range I9:I18 could be empty.
So the code continues to run & i then see the msgbox "All figures have been transfered.

So i added the extra code in red below to it to first check but then this is where i now fail for it to run correctly.

Rich (BB code):
Private Sub AprilStartButton_Click()
If WorksheetFunction.CountA(Range("I9:I18")) = 0 Then
MsgBox "THERE ARE NO VALUES TO TRANSFER", vbCritical
Else

If WorksheetFunction.CountA(Range("B4:B13")) > 0 Then
    answer = MsgBox("CELLS CONTAIN VALUES ALREADY, OVERWRITE THEM ?", vbCritical + vbYesNo)
    If answer = vbNo Then
      Exit Sub
    End If
End If
   
Range("I9:I18").Copy Destination:=Range("B4:B13")
MsgBox "ALL FIGURES HAVE BEEN TRANSFERED", vbInformation, "MONTHS FIGUES MESSAGE"
Unload SUMMARYSHEETYEAR
Range("I9:I18").ClearContents
Range("I9").Select
ActiveWorkbook.Save

End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
How about replacing this :
VBA Code:
If WorksheetFunction.CountA(Range("I9:I18")) = 0 Then
    MsgBox "THERE ARE NO VALUES TO TRANSFER", vbCritical
Else

With this:
VBA Code:
    If WorksheetFunction.CountA(Range("I9:I18")) = 0 Then
        MsgBox "THERE ARE NO VALUES TO TRANSFER", vbCritical
        Exit Sub
    End If
 
Upvote 0
This works but please check it anyway

Thanks

Rich (BB code):
Private Sub AprilStartButton_Click()
If WorksheetFunction.CountA(Range("I9:I18")) = 0 Then
MsgBox "THERE ARE NO VALUES TO TRANSFER", vbCritical

Else
If WorksheetFunction.CountA(Range("B4:B13")) > 0 Then
    answer = MsgBox("CELLS CONTAIN VALUES ALREADY, OVERWRITE THEM ?", vbCritical + vbYesNo)
    If answer = vbNo Then
      Exit Sub
    End If
End If
    
Range("I9:I18").Copy Destination:=Range("B4:B13")
MsgBox "ALL FIGURES HAVE BEEN TRANSFERED", vbInformation, "MONTHS FIGUES MESSAGE"
Unload SUMMARYSHEETYEAR
Range("I9:I18").ClearContents
Range("I9").Select
ActiveWorkbook.Save
End If

End Sub
 
Upvote 0
This works but please check it anyway

Thanks

Rich (BB code):
Private Sub AprilStartButton_Click()
If WorksheetFunction.CountA(Range("I9:I18")) = 0 Then
MsgBox "THERE ARE NO VALUES TO TRANSFER", vbCritical

Else
If WorksheetFunction.CountA(Range("B4:B13")) > 0 Then
    answer = MsgBox("CELLS CONTAIN VALUES ALREADY, OVERWRITE THEM ?", vbCritical + vbYesNo)
    If answer = vbNo Then
      Exit Sub
    End If
End If
   
Range("I9:I18").Copy Destination:=Range("B4:B13")
MsgBox "ALL FIGURES HAVE BEEN TRANSFERED", vbInformation, "MONTHS FIGUES MESSAGE"
Unload SUMMARYSHEETYEAR
Range("I9:I18").ClearContents
Range("I9").Select
ActiveWorkbook.Save
End If

End Sub
Thta should also work .
 
Upvote 0
Solution

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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