+ Reply to Thread
Results 1 to 5 of 5

How to define range based on the value of another cell

  1. #1
    Registered User
    Join Date
    10-25-2019
    Location
    Reading, England
    MS-Off Ver
    2010
    Posts
    1

    Post How to define range based on the value of another cell

    Is it possible to define a range in VBA based on a value given in a cell?

    For example, I have a dataset with a constantly changing number of rows. I have the number of rows in cell B2. Suppose cell B2 indicates the number of rows is 33, then I want the range to be D5: D33, but I want the selection of the last cell to be dependent on cell B2.
    So if I change B2 to 50, the next time I run the macro, D5: D50 will be selected, but since I'm new to VBA I can't figure it out.

    Thanks in advance for your help

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to define range based on the value of another cell

    in VBA
    Please Login or Register  to view this content.
    in a worksheet formula something like =SUM(D5:INDEX(D:D,B2,1))
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,409

    Re: How to define range based on the value of another cell

    Try
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to define range based on the value of another cell

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,409

    Re: How to define range based on the value of another cell

    Why do you need the rows in cell B2?

    You could use:
    Please Login or Register  to view this content.

+ 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] Define Name range based on cell value
    By mahmud9935 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-22-2015, 07:23 AM
  2. [SOLVED] Define new range names based on existing range name offset 1 column to right
    By jprlimey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2014, 07:53 PM
  3. Define % used based on value range?
    By Kayto in forum Excel General
    Replies: 6
    Last Post: 11-27-2013, 12:25 PM
  4. [Solved] Define range of formula on VBA based on first blank cell
    By kurtwagner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-25-2012, 12:32 PM
  5. How to define a range based on (variable) cell values
    By bubastisbastet in forum Excel General
    Replies: 4
    Last Post: 03-13-2010, 07:45 AM
  6. define range based on cell value in another column
    By samshut in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-11-2007, 07:25 PM
  7. define/name a range based on a formula?
    By BigBas in forum Excel General
    Replies: 8
    Last Post: 03-15-2007, 02:17 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