Sub Structure error

Hi,

I have put together a sub but am getting two errors, one saying Loop without Do and the other saying If without End f

I cant see the problem, can someone point it out please!

Thanks
Seamus
Sub SumUpForTable()
Dim FoundCell As Range

 Sheets("Corporate Actions").Select
    Range("B3").Select
    
        Do Until ActiveCell.Value = ""
            mysheetname = ActiveCell.Text
                Sheets(mysheetname).Select
                    If Range("A2").Value = "" Then
                                       
                Sheets("Corporate Actions").Select
               ActiveCell.Offset(0, 1).Value = "0"
               ActiveCell.Offset(0, 2).Value = "0"
                
            ActiveCell.Offset(1, 0).Select
        
        
        Else
    
  

    
    Set FoundCell = Columns("C:C").Find(What:="Grand Total", LookIn:=xlValues, _
        lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
 


   With FoundCell
      .Offset(0, 7).Select

       ActiveCell.Resize(1, 2).Select
        Selection.Copy
        
        Sheets("Corporate Actions").Select
     ActiveCell.Offset(0, 1).PasteSpecial Paste:=xlPasteValues
        
        
     

             
            Loop

        
        
         End With
        Range("C3:C23").Select
    Selection.NumberFormat = "#,##0"
         
End Sub

Open in new window

Seamus2626Asked:
Who is Participating?
 
EyalCommented:
keep your code in the proper indentation and it will be easy to find such errors

    Sub SumUpForTable()
        Dim FoundCell As Range

        Sheets("Corporate Actions").Select()
        Range("B3").Select()

        Do Until ActiveCell.Value = ""
            mysheetname = ActiveCell.Text
            Sheets(mysheetname).Select()
            If Range("A2").Value = "" Then

                Sheets("Corporate Actions").Select()
                ActiveCell.Offset(0, 1).Value = "0"
                ActiveCell.Offset(0, 2).Value = "0"
                ActiveCell.Offset(1, 0).Select()
            Else
                FoundCell = Columns("C:C").Find(What:="Grand Total", LookIn:=xlValues, _
                    lookat:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                    MatchCase:=False, SearchFormat:=False)
            End If
            With FoundCell
                .Offset(0, 7).Select()
                ActiveCell.Resize(1, 2).Select()
                Selection.Copy()
                Sheets("Corporate Actions").Select()
                ActiveCell.Offset(0, 1).PasteSpecial(Paste:=xlPasteValues)
            End With
        Loop
        Range("C3:C23").Select()
        Selection.NumberFormat = "#,##0"
    End Sub

Open in new window

0
 
Seamus2626Author Commented:
Thank you, i found the error and will post for a solution

Seamus
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.