End If without Block If AND Block If without End If Error

bob12321

New Member
Joined
Aug 22, 2013
Messages
13
Okay so below is the code. Basically what happens is that the compiler throws an "end if without block if" error and when I add an end if where required, it throws a "block if without end if" error - so what am I missing in the code then?

Code:
Private Sub UpdateCommentPic(ByVal Rowno As Integer, ByVal column As String, ByVal piclocation As String) Set MyImg = LoadPicture(piclocation)
  Dim H As Long
  Dim W As Long
  H = MyImg.Height
  W = MyImg.Width
 Dim RowNumber As String
    RowNumber = row
    Dim cell As String
    cell = column & RowNumber
    Dim c As Comment
    With Range(cell)
    On Error Resume Next
    Set c = .Comment
    On Error GoTo 0
    If c Is Nothing Then
        Dim commentBox As Comment
        Set commentBox = Sheet1.Range(cell).AddComment
        With commentBox
        .text text:=""
        With .Shape
        .Fill.UserPicture (piclocation)
        .Height = H / 27
        .Width = W / 27
        End With
        If piclocation = ActiveWorkbook.Path & "\Main Pics\No Photo.jpg" Then
            Sheet1.Range(cell).Comment.Delete
        Else
            Sheet1.Range(cell).Comment.Delete
            Dim commentBoxtwo As Comment
            Set commentBoxtwo = Sheet1.Range(cell).AddComment
            With commentBoxtwo
            .text text:=""
            With .Shape
           .Fill.UserPicture (piclocation)
           .Height = H / 27
           .Width = W / 27
            End With
        End If
End If
 End With
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
I can't explain why, but the problem seems to be that your WITH statements are interferring with the IF statements.

I tried toning down the use of with and it compiled:

Code:
Private Sub UpdateCommentPic(ByVal Rowno As Integer, ByVal column As String, ByVal piclocation As String)

    Set MyImg = LoadPicture(piclocation)
  
  Dim H As Long
  Dim W As Long
  H = MyImg.Height
  W = MyImg.Width
 Dim RowNumber As String
    RowNumber = Row
    Dim cell As String
    cell = column & RowNumber
    Dim c As Comment
    With Range(cell)
    On Error Resume Next
    Set c = .Comment
    On Error GoTo 0
    
    
    If c Is Nothing Then
        Dim commentBox As Comment
        Set commentBox = Sheet1.Range(cell).AddComment
        With commentBox
        .Text Text:=""
        End With
            
        With commentBox.Shape
        .Fill.UserPicture (piclocation)
        .Height = H / 27
        .Width = W / 27
        End With
                
                If piclocation = ActiveWorkbook.Path & "\Main Pics\No Photo.jpg" Then
                     Sheet1.Range(cell).Comment.Delete
                Else
                     Sheet1.Range(cell).Comment.Delete
                     Dim commentBoxtwo As Comment
                     Set commentBoxtwo = Sheet1.Range(cell).AddComment
                     With commentBoxtwo
                     .Text Text:=""
                     End With
                     With commentBoxtwo.Shape
                    .Fill.UserPicture (piclocation)
                    .Height = H / 27
                    .Width = W / 27
                     End With
                End If
    
    End If

 
 End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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