+ Reply to Thread
Results 1 to 4 of 4

Compile error:

  1. #1
    Registered User
    Join Date
    11-08-2022
    Location
    Davenport, IA
    MS-Off Ver
    MS 360
    Posts
    15

    Compile error:

    Hello,

    I am trying to create a macro to select E2, then run a formula within an autofill based off of column A.

    Sub Formula()
    'Assign a flexible formula to a range of cells
    For x = 2 To 1000
    If range("A" & x).Value = Then range("E" & x).Formula2R1C1 = right(D2,5)


    End Sub

    My error is "then"

  2. #2
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Compile error:

    This would be the right syntax:
    Please Login or Register  to view this content.
    You need to say to what "Range("A" & x).Value" is equal to and note the double-quotes arround the formula.

  3. #3
    Registered User
    Join Date
    11-08-2022
    Location
    Davenport, IA
    MS-Off Ver
    MS 360
    Posts
    15

    Re: Compile error:

    Hello,

    thank you for a quick response, I have updated my macro but now receive an error message of "without next"
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor rollis13's Avatar
    Join Date
    01-26-2012
    Location
    Cordenons
    MS-Off Ver
    Excel 2016 32bit - Win 11
    Posts
    935

    Re: Compile error:

    That's right and that's why they call the loop a For/Next; so this is how your macro should be:
    Please Login or Register  to view this content.
    Then you will need to valorize the variable what telling VBE it's content, I mean, what should contents of Range("A" & x).Value be equal to ?
    By the way, why are you using .Formula2R1C1 instead of .FormulaR1C1 ?
    You should also add as first line of your panel Option Explicit. It will help with debugging and avoid/indicate some other errors.
    Last edited by rollis13; 11-17-2022 at 05:18 PM.

+ 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. Compile Error: compile error constant expression required.
    By countryfan_nt in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-30-2019, 04:45 AM
  2. [SOLVED] Compile Error: Wrong number of arguments or invalid property assignment Error
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-22-2016, 05:29 PM
  3. Excel macro (compile error. syntax error.) error
    By salar_younis in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-06-2014, 06:11 AM
  4. [SOLVED] Compile Error in Hidden Module and Compile Error: Can't find project or library
    By Taislin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-10-2013, 07:03 PM
  5. Syntax Error and Compile Error: Expected Line Number or Label...
    By AnthonyWB in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-31-2011, 09:59 AM
  6. compile error: compile error expected
    By odeno in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2008, 04:30 PM
  7. [SOLVED] VBAProject name compile error, not defined at compile time
    By Matthew Dodds in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-13-2005, 03:20 PM

Tags for this Thread

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