+ Reply to Thread
Results 1 to 3 of 3

How to have a dynamic Range in VBA in Excel?

  1. #1
    Registered User
    Join Date
    04-14-2014
    Location
    Philippines
    MS-Off Ver
    Excel 2010
    Posts
    97

    How to have a dynamic Range in VBA in Excel?

    Hi everyone!

    I have the code below to run for Paste Special (xlPasteFormulas, xlPasteValues)

    Please Login or Register  to view this content.

    ------My concern is how to make the . Range("AC6:AC11880") & .Range("AB5:AB11880") dynamic,
    so that when I am going to add "4 or more Data" the Range should also be increasing to something like . Range("AC6:AC11884") & .Range("AB5:AB11884)

    Any help is really appreciated.

    Thanks in advance,

    Rev12
    Last edited by Rev12; 06-16-2018 at 10:16 AM. Reason: wrap codes

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: How to have a dynamic Range in VBA in Excel?

    Hi Rev12,

    There are two possible answers to your question. First is by using Dynamic Named Ranges in the Formulas Named Ranges tool. Then use the named range in your VBA instead of the range letters.

    See https://www.vertex42.com/blog/excel-...ed-ranges.html and to use the named range in your vba see:
    https://excel.tips.net/T003106_Using...n_a_Macro.html

    Second would be to find the last entry in one of your longest column using a VBA variable. I like to create a variable called LastRow so I can remember what it is. Then:
    Please Login or Register  to view this content.
    Then instead of using your

    Please Login or Register  to view this content.
    I'd make it..

    Please Login or Register  to view this content.
    Read: https://www.thespreadsheetguru.com/b...lumn-using-vba

    I hope this helps.
    Last edited by jeffreybrown; 06-16-2018 at 07:39 PM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,546

    Re: How to have a dynamic Range in VBA in Excel?

    Or for individual lengths of Columns:
    Please Login or Register  to view this content.
    becomes
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    becomes
    Please Login or Register  to view this content.
    More typing though!

+ 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. Match ComboBox with dynamic range, then add Textbox1 to dynamic range
    By Lasse Moe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2014, 01:26 AM
  2. Excel reset my dynamic name range
    By Sashen in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 03-19-2013, 02:11 PM
  3. Dynamic Range Column Chart w/ Dynamic Avg Line (Excel 2007)
    By BrokenBiker in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 10-04-2012, 11:40 AM
  4. Excel Dynamic Range
    By s1joshi in forum Excel General
    Replies: 5
    Last Post: 01-31-2010, 03:29 PM
  5. Dynamic Range Excel 2003
    By mattydalton in forum Excel General
    Replies: 4
    Last Post: 11-05-2009, 07:37 AM
  6. Dynamic Range in Excel
    By TCameron in forum Excel General
    Replies: 4
    Last Post: 07-28-2008, 05:13 PM
  7. [SOLVED] dynamic range for excel chart
    By bobf in forum Excel General
    Replies: 1
    Last Post: 01-26-2005, 08:06 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