Consulting

Results 1 to 7 of 7

Thread: END IF WITHOUT BLOCK IF

  1. #1
    VBAX Newbie
    Joined
    Apr 2016
    Posts
    2
    Location

    END IF WITHOUT BLOCK IF

    Hi,

    I have been trying to write an IF but keep getting the compile error "END IF WITHOUT BLOCK IF", here is my code:

    Sub COPYPAST010416()
    '
    ' COPYPAST010416 Macro
    '
    '
       ' If CheckBox1.Value = True Then
       Do
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        ActiveWindow.SmallScroll Down:=-48
        Range("A1").Select
        ActiveWindow.ScrollColumn = 2
        ActiveWindow.ScrollColumn = 3
        ActiveWindow.ScrollColumn = 4
        Range("T6").Select
        Do
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("Ing PPV").Select
        ActiveWindow.SmallScroll Down:=0
        Do
        Range("F7").Select
        Range(Selection, Selection.End(xlDown)).Select
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Copy
        Do
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
            
            End If
            End Sub



    Please can you help
    Last edited by SamT; 04-01-2016 at 08:14 PM.

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Your Do's don't have matching Loop lines.

    Do...Loop is a structure to loop commands, but looping doesn't seem appropriate for that routine. What are you trying to achieve and what do you think that the Do lines are doing?

  3. #3
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    You have an 'End If' right before 'End Sub'. The error message if telling you that you are lacking an 'If [test] Then' to match the 'End If'. You also have a bunch of 'Do'(s) that have no corresponding 'Loop'(s).

  4. #4
    VBAX Newbie
    Joined
    Apr 2016
    Posts
    2
    Location
    I have taken out the Do's, I basically need it to look at Checkbox1 and if it is ticked I need it to a range of cells and paste them somewhere else,. If the checkbox is unticked then I don't want it to do anything, :S

  5. #5
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Did the removal of the Do's fix the problem?
    If not, what cells do you want copied and where do you want them to be put?

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    I'm not sure what your intent is, but I've found that 'blocking' and indenting helps the readability (the If and End If)

    Usually do not need to select something if you're going to use or operate on it. That's usually the first thing I change after I record a macro

    The macro recorder records all the misc clicking and scrolling so I delete them also

    Option Explicit
    
    Sub COPYPAST010416()
        If CheckBox1.Value = True Then
                Range(Selection, Selection.End(xlDown)).Copy
                
                Range("T6").Select
                Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
                
                Sheets("Ing PPV").Select
                Range("F7").Copy
                Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
        End If
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    From Pauls' example
     
    Sub COPYPAST010416() 
        If CheckBox1 <> -1 Then Exit Sub
    
    With ActiveSheet
        Range(Selection, Selection.End(xlDown)).Copy 
        Range("T6").PasteSpecial Paste:=xlPasteValues
    End With
             
        With  Sheets("Ing PPV").Range("F7")
               .Value = .Value
         End With
     End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •