+ Reply to Thread
Results 1 to 6 of 6

Compile error: Expected end of statement

Hybrid View

  1. #1
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Lightbulb Compile error: Expected end of statement

    Sub big_v()
        Dim LastRow As Variant
        Dim Lastcolumn As Variant
        Dim count1 As Long
        Dim count2 As Long
        Dim count3 As Long
        count3 = 10
        LastRow = Range("C6").End(xlDown).Row
        LastRow = -1 * (LastRow)
        Lastcolumn = ThisWorkbook.Worksheets("Data Sheet").Cells(3, 5)
        Lastcolumn = -1 * (Lastcolumn + 10)
        count2 = -3
        For count1 = -7 To Lastcolumn Step -1
            .Cells(6, count3).Select
            ActiveCell.FormulaR1C1 = "=VLOOKUP(RC["count1"],Sheet1!C["count1"]:C["count2"],5,FALSE)"
            count3 = count3 + 1
            count2 = count2 - 1
        Next count1
            
    End Sub


    i want to put the counters in the [] brackets but i get a compile error expected end of stantement
    Last edited by RoOmIE; 10-08-2013 at 11:20 AM.

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Compile error: Expected end of statement

    you need to add & signs when switching from strings to variables in your formula definition:
    ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[" & count1 & "],Sheet1!C[" & count1 & "]:C[" & count2 & "],5,FALSE)"

  3. #3
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Compile error: Expected end of statement

       Range("j6").Select
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[count1],Sheet1!C[count1]:C[count2],5,FALSE)"
      
        Range("K6").Select
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-8],Sheet2!C[-8]:C[-4],5,FALSE)"
        Range("L6").Select
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-9],Sheet3!C[-9]:C[-5],5,FALSE)"
        Range("M6").Select
        ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-10],Sheet4!C[-10]:C[-6],5,FALSE)"
        Range("J6:M6").Select
    this is sort of what i want to do ..

  4. #4
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Compile error: Expected end of statement

    thanks yudlugar ... now if i want to change sheets at every count .. how would i do this ..

  5. #5
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Compile error: Expected end of statement

     ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[" & count1 & "],Sheet" & count3 - 9 & "!C[" & count1 & "]:C[" & count2 & "],5,FALSE)"
    ?

  6. #6
    Registered User
    Join Date
    08-30-2013
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    95

    Re: Compile error: Expected end of statement

    Thanks.. i am somewhat not used to the language of vba .. but am learning .. thanks a lot!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Compile Error: Expected: End of Statement
    By eemiller1997 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-14-2012, 09:37 AM
  2. [SOLVED] Compile error: Expected end of statement
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 07:12 PM
  3. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  4. Compile Error Expected: End of statement
    By AKarmyguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2010, 02:20 AM
  5. How to fix a Compile Error Expected: End of statement.
    By AKarmyguy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-03-2010, 02:19 AM

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