End if without block if ??

travelboo

New Member
Joined
Feb 21, 2011
Messages
5
Why is this not working ?? Any ideas people ?


sub()

For i = 1 To 2
If i = 1 Then Worksheets("EUR Collection").Select
If i = 2 Then Worksheets("GBP Collection").Select
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
Rows("6:6").Select
Range("D6").Activate
Application.CutCopyMode = False
Selection.Copy
Rows(finalrow).Offset(-49).Resize(50).Select
Rows(finalrow).Offset(-49).Resize(50).Activate
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
i = i + 1


End If
Next i

end sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Your syntax is incorrect, try:
Code:
Sub MyMacro()
For i = 1 To 2
  If i = 1 Then Worksheets("EUR Collection").Select
  If i = 2 Then Worksheets("GBP Collection").Select
  finalrow = Cells(Rows.Count, 1).End(xlUp).Row
  Range("D6").Copy
  Rows(finalrow).Offset(-49).Resize(50).PasteSpecial Paste:=xlPasteFormats
Next i
End sub
 
Upvote 0
You had an extraneous End If. Try

Code:
Sub test2()

For i = 1 To 2
    If i = 1 Then
        Worksheets("EUR Collection").Select
    ElseIf i = 2 Then
        Worksheets("GBP Collection").Select
    End If
    finalrow = Cells(Rows.Count, 1).End(xlUp).Row
    Rows("6:6").Select
    Range("D6").Activate
    Selection.Copy
    Rows(finalrow).Offset(-49).Resize(50).Select
    Rows(finalrow).Offset(-49).Resize(50).Activate
    Selection.PasteSpecial Paste:=xlPasteFormats
    Application.CutCopyMode = False
Next i

End Sub
 
Upvote 0
Both of your If statements use the single line form, so there is no need for your End If statement.
 
Upvote 0
It looks to me like you're missing an End If. You have two If statements but you are only closing one of them at the end.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,752
Members
452,940
Latest member
rootytrip

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