+ Reply to Thread
Results 1 to 15 of 15

Compile Error: Variable Not Defined

  1. #1
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Compile Error: Variable Not Defined

    Getting the above error when I try to run the code in the attached worksheet.

    Set My Data is highlighted; any suggestions?

    'Open target worksheet
    Set myData = Workbooks.Open("C:\Users\The GaffeR\Desktop\Target.xlsx")
    Book3.xlsm
    ?True friends stab you in the front.?

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile Error: Variable Not Defined

    Try
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Re: Compile Error: Variable Not Defined

    Done that jaslake; now throws the same error code for RowCount...do I need to declare RowCount as a variable?

    'Find last empty row
    RowCount = Worksheets("sheet1").Range("A1").CurrentRegion.Rows.Count

  4. #4
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Re: Compile Error: Variable Not Defined

    Done that jaslake; now throws the same error code for RowCount...do I need to declare RowCount as a variable also?

    'Find last empty row
    RowCount = Worksheets("sheet1").Range("A1").CurrentRegion.Rows.Count
    Last edited by Limitedtimeonearth; 06-02-2013 at 01:53 PM. Reason: duplicate post

  5. #5
    Registered User
    Join Date
    03-04-2012
    Location
    Lodz, Poland
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: Compile Error: Variable Not Defined

    Yeap. It's recommended to declare variables. VBA allows not to declare variables by turning off Option Explicit statement but it is not recommended.

    MSDN quote concerning Option Explicit and declaring variables:
    Use Option Explicit to avoid incorrectly typing the name of an existing variable or to avoid confusion in code where the scope of the variable is not clear. If you do not use the Option Explicit statement, all undeclared variables are of Object type.

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile Error: Variable Not Defined

    Hi Limited

    Yes...
    Please Login or Register  to view this content.

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Compile Error: Variable Not Defined

    Hi, Limitedtimeonearth,

    I always wonder where people find codes like the one you used - why not just use
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  8. #8
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Re: Compile Error: Variable Not Defined

    jaslake,

    Thanks for your time fella; appreciated.

    HaHoBe,

    Haven't got time to play with your code tonight but appreciate the time and effort you've put in to producing it for me. I'll try your code over the next few days; looks a lot tidier than what I'm using (he said pretending he knows what he's on about ) but there is some mileage in me persevering with the original code if only to gain some learning re vba coding.

    Cheers guys

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Compile Error: Variable Not Defined

    You're welcome...glad I could help. Thanks for the Rep.

  10. #10
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Compile Error: Variable Not Defined

    Hi, Limitedtimeonearth,

    I tend to use as few varaibles as needed (sometimes I alter the way to solve a problem and then have some being dimmed but not used). But letīs get more practical. Right now the code copies the second row of the worksheet you start in. Just imagine to change the code you use right now to reflect the last row used.

    BTW: as this is solved please mark the thread as this. Thanks.

    Ciao,
    Holger

  11. #11
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Re: Compile Error: Variable Not Defined

    Tried replacing: lngFF = .Range("A" & Rows.Count).End(xlUp).Row + 1
    with:

    Last Row = .Range("A" & Rows.Count).End(xlUp).Row + 1

    but didn't work....hmmmm

  12. #12
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Re: Compile Error: Variable Not Defined

    Maybe I need to declare Last Row as a variable?

  13. #13
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Re: Compile Error: Variable Not Defined

    Nope; that won't work either

  14. #14
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Re: Compile Error: Variable Not Defined

    Opps; forgot to "lose" the space between Last and Row....

  15. #15
    Registered User
    Join Date
    04-17-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    38

    Re: Compile Error: Variable Not Defined

    Will start new thread...

+ 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