+ Reply to Thread
Results 1 to 5 of 5

VBA naming a range works but not when referenced later in code

  1. #1
    Registered User
    Join Date
    11-11-2020
    Location
    Australia
    MS-Off Ver
    microsoft 365
    Posts
    3

    Question VBA naming a range works but not when referenced later in code

    Hi all,

    Been learning how to utilize VBA in my excel creations and have come across something i just cannot make work. The goal is to use the number in cell AO2 as the row number to fill down to. Code works it i enter a range in there but i need it to be dependant on AO2 value. Error seems to be here =Range(Rng1)

    Can anyone provide a solution?

    Thanks in advance.

    ...........................................................................

    Please Login or Register  to view this content.
    Last edited by AliGW; 11-11-2020 at 04:14 AM.

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA naming a range works but not when referenced later in code

    Please post code within [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags.

    What your code is doing is trying to fill columns "A" to "AH" into a single column Rng1 ("A3:A?"), and that's probably why it failed.

    For such a simple operation, you don't really need any variables for that.
    Please Login or Register  to view this content.
    多么想要告诉你 我好喜欢你

  3. #3
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Ipswich, England
    MS-Off Ver
    MS 365 Subscription Insider (Windows 11 64-bit)
    Posts
    52,502

    Re: VBA naming a range works but not when referenced later in code

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new, I have done it for you today.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!

    Forum Rules (updated September 2018): please read them here.
    How to use the Power Query code you've been given: help here. More about the Power suite here.
    Don't forget to say "thank you" to those who have helped you in your thread. If you wish, you can also reward them by clicking on their reputation star bottom left.

  4. #4
    Registered User
    Join Date
    11-11-2020
    Location
    Australia
    MS-Off Ver
    microsoft 365
    Posts
    3

    Re: VBA naming a range works but not when referenced later in code

    Thankyou so much. Works a treat. I did have press code at the start but i didnt think it worked so i deleted the codes. Will put them on next time.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Ipswich, England
    MS-Off Ver
    MS 365 Subscription Insider (Windows 11 64-bit)
    Posts
    52,502

    Re: VBA naming a range works but not when referenced later in code

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ 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] Re-naming a sheet, works but with errors
    By Barttm888 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-18-2015, 09:02 AM
  2. Replies: 3
    Last Post: 06-14-2014, 08:15 PM
  3. Migration from Excel 2003 to Excel 2007 and chart naming code no longer works...
    By SteHawk85 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 10-05-2012, 10:14 AM
  4. Formula only works with referenced workbooks open
    By woodrbw in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-19-2012, 07:26 AM
  5. VBA code to convert absolute to semi-relative referenced range
    By gpk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-29-2011, 07:40 AM
  6. Naming a Range Code:formula is then copied
    By dgo in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-08-2009, 09:13 AM
  7. Tab-naming macro only works once :-(
    By Stilla in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-10-2006, 11:15 AM

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