+ Reply to Thread
Results 1 to 10 of 10

Range variable question

  1. #1
    Registered User
    Join Date
    04-26-2007
    Posts
    94

    Range variable question

    I have a range "C1:Cx" where i want x to be the value from a value "overallLastRow". How do I write this?

    Thanks
    Dave

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Just a reminder to post to the right group next time.

    Maybe

    Range("C1:C" & x)
    to find last then see links

    http://www.rondebruin.nl/last.htm

    http://www.ozgrid.com/VBA/ExcelRanges.htm

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    04-26-2007
    Posts
    94
    Thanks VBA noob. I have the findlast sorted already.

    I am now trying to add a similar piece of code into a more complex section:

    Range("A1").FormulaR1C1 = "=IF(ISERROR(MATCH(old!$C$1:$C$x,new!$C$1:$C$x,0)),old!$C$1:$C$x,"")"
    Can you tell me how to make x overallLastRow in this instance?

    Thanks Again
    Dave

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Instead of FormulaR1C1 try Formula

    You may need to post the actual formula but try something like

    Please Login or Register  to view this content.
    VBA Noob

  5. #5
    Registered User
    Join Date
    04-26-2007
    Posts
    94
    Quote Originally Posted by VBA Noob
    Instead of FormulaR1C1 try Formula

    You may need to post the actual formula but try something like

    Please Login or Register  to view this content.
    VBA Noob

    I get Run-Time Error '1004'

    Application defined or object defined error

    Please Login or Register  to view this content.
    I have substituted x for overallLastRow, but have this error.

  6. #6
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Your still using the R1C1 format

    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.
    You may need to post the actual formula but try something like
    Then post the formula as it would be displayed in a cell.

    VBA Noob

  7. #7
    Registered User
    Join Date
    04-26-2007
    Posts
    94
    I now have:

    Please Login or Register  to view this content.
    Still have the same error.

  8. #8
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Which line does it stop at.

    See if this helps

    Please Login or Register  to view this content.
    VBA Noob

  9. #9
    Registered User
    Join Date
    04-26-2007
    Posts
    94
    Ah, thanks. I've spotted it.

    See amendment in bold:

    Range("A1").Formula = "=IF(ISERROR(MATCH(old!$C$1:$C$" & overallLastRow & ",new!$C$1:$C$" & overallLastRow & " ,0)),old!$C$1:$C$" & overallLastRow & " ,"")"

    Range("A1").Formula = "=IF(ISERROR(MATCH(old!$C$1:$C$" & overallLastRow & ",new!$C$1:$C$" & overallLastRow & " ,0)),old!$C$1:$C$" & overallLastRow & " ,"""")"

  10. #10
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Glad you got it sorted

    Double quotes get you every time.

    I usually write the formula then turn on the recorder and enter a ' in front of the formula to get

    Please Login or Register  to view this content.
    Then remove the R1C1 and the '

    HTH

    VBA Noob

+ 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