PDA

View Full Version : END IF WITHOUT BLOCK IF



kkkaura
04-01-2016, 06:35 AM
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

mikerickson
04-01-2016, 06:38 AM
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?

GTO
04-01-2016, 06:39 AM
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).

kkkaura
04-01-2016, 06:45 AM
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

mikerickson
04-01-2016, 06:56 AM
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?

Paul_Hossler
04-01-2016, 07:19 AM
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

SamT
04-01-2016, 08:30 PM
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