+ Reply to Thread
Results 1 to 5 of 5

Compile Error

Hybrid View

  1. #1
    Registered User
    Join Date
    02-19-2009
    Location
    Cambridgeshire, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Compile Error

    Dear All,

    After lots of help yesterday from RoyUK, I now have the following macro. However, this gives me a compile error Block if without End If but I do have an End If statement.

    Sub Copy_Balances_to_Database()
        ActiveWindow.ScrollWorkbookTabs Position:=xlLast
        Sheets("Variance").Select
        Range("A4:D447").Select
        Selection.Copy
        Workbooks.Open fileName:= _
            "V:\Treasury Group\PLC Treasury Folders\Annabel F\Projects\UK Cash Spreadsheet\Bank Balance database.xls"
        Sheets("Worksheet").Select
        Range("F2").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        Sheets("TC GBP Pooled").Select
        Dim DateRng As Range
        Dim cl     As Range
        Dim dte    As Date
        With Worksheets("TC GBP Pooled")
            dte = CDate(Cells(1, 2).Value)
            Set DateRng = .Range(.Cells(4, 1), .Cells(.Rows.Count, 1).End(xlUp))
            Set cl = DateRng.Find(dte, LookIn:=xlValues)
            If Not cl Is Nothing Then
                Sheets("Worksheet").Range("C2:C31").Copy
                cl.Offset(, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False _
                , Transpose:=True
        Sheets("TC GBP Non Pooled").Select
        With Worksheets("TC GBP Non Pooled")
            dte = CDate(Cells(1, 2).Value)
            Set DateRng = .Range(.Cells(4, 1), .Cells(.Rows.Count, 1).End(xlUp))
            Set cl = DateRng.Find(dte, LookIn:=xlValues)
            If Not cl Is Nothing Then
                Sheets("Worksheet").Range("C34:C39").Copy
                cl.Offset(, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False _
                , Transpose:=True
        Sheets("USD").Select
        With Worksheets("USD")
            dte = CDate(Cells(1, 2).Value)
            Set DateRng = .Range(.Cells(4, 1), .Cells(.Rows.Count, 1).End(xlUp))
            Set cl = DateRng.Find(dte, LookIn:=xlValues)
            If Not cl Is Nothing Then
                Sheets("Worksheet").Range("C43:C58").Copy
                cl.Offset(, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False _
                , Transpose:=True
        Sheets("EUR").Select
        With Worksheets("EUR")
            dte = CDate(Cells(1, 2).Value)
            Set DateRng = .Range(.Cells(4, 1), .Cells(.Rows.Count, 1).End(xlUp))
            Set cl = DateRng.Find(dte, LookIn:=xlValues)
            If Not cl Is Nothing Then
                Sheets("Worksheet").Range("C61:C78").Copy
                cl.Offset(, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False _
                , Transpose:=True
        Sheets("CAD").Select
        With Worksheets("CAD")
            dte = CDate(Cells(1, 2).Value)
            Set DateRng = .Range(.Cells(4, 1), .Cells(.Rows.Count, 1).End(xlUp))
            Set cl = DateRng.Find(dte, LookIn:=xlValues)
            If Not cl Is Nothing Then
                Sheets("Worksheet").Range("C81:C85").Copy
                cl.Offset(, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False _
                , Transpose:=True
        Sheets("Other Currency").Select
        With Worksheets("Other Currency")
            dte = CDate(Cells(1, 2).Value)
            Set DateRng = .Range(.Cells(4, 1), .Cells(.Rows.Count, 1).End(xlUp))
            Set cl = DateRng.Find(dte, LookIn:=xlValues)
            If Not cl Is Nothing Then
                Sheets("Worksheet").Range("C88:C114").Copy
                cl.Offset(, 2).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False _
                , Transpose:=True
        Application.CutCopyMode = False
        ActiveWorkbook.Save
        ActiveWorkbook.Close
        ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
        Sheets("Process").Select
            End If
        End With
    End Sub
    Any ideas?

    Thanks
    DB

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Compile Error

    For each "If" in your code you need an "End If". Having one at the end will not suffice, alas.

  3. #3
    Registered User
    Join Date
    02-19-2009
    Location
    Cambridgeshire, England
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Compile Error

    Thank you!

    It would be something that simple!!

    my macro now works beautifully so thank you very much!

  4. #4
    Forum Contributor mewingkitty's Avatar
    Join Date
    09-29-2008
    Location
    Fort McMurray, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    949

    Re: Compile Error

    May want to note:
    Sometimes you will get a "NEXT with no FOR" error, when in fact it's an ENDIF that you're missing.

    mew!
    =IF(AND(OR(BLONDE,BRUNETTE,REDHEAD),OR(MY PLACE,HER PLACE),ME),BOW-CHICKA-BOW-WOW,ANOTHER NIGHT ON THE INTERNET)

  5. #5
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Compile Error

    Dumb Blonde

    Your post does not comply with Rule 9 of our Forum RULES. If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit. And please never edit a thread in which someone else has responded.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1