+ Reply to Thread
Results 1 to 5 of 5

Adaptive cell range

Hybrid View

Trevasaurus Adaptive cell range 05-10-2013, 02:46 PM
NeedForExcel Re: Adaptive cell range 05-10-2013, 03:38 PM
Trevasaurus Re: Adaptive cell range 05-13-2013, 12:04 PM
NeedForExcel Re: Adaptive cell range 05-13-2013, 01:48 PM
Trevasaurus Re: Adaptive cell range 05-14-2013, 11:34 AM
  1. #1
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Adaptive cell range

    Hey,

    I'm trying to get a cell range to increase to match my data size, every time the macro is ran.

    Basically, I have a range ("B2:K20") that I'm copying and pasting over one column, to ("C2:L20").

    Now, the next time I run the macro to copy and paste this range, the range I want to capture is 1 column larger. So the next range, after copying and pasting the first range to the right, would be ("B2:L20").

    How can I make my range equal the number of columns I want to capture? It might help to add that there is nothing to the right of the cell range I'm trying to target.

    Thanks in advance

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Adaptive cell range

    Hey!!

    You will have to find the Last Column. You can use -

    Dim LC as Integer
    
    LC = Cells(2,Columns.Count).End(XLToLeft).Column
    Then you can refer the Range using LC in place of Column References.

    Thank You,

    Deep
    Cheers!
    Deep Dave

  3. #3
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Re: Adaptive cell range

    Hey ExcelatHome

    Thanks for the code. I'm trying to insert it into my macro but there's something wrong with my syntax.
    I'm not sure how to add that integer into my cell range. Any help is appreciated. This is what I have so far.

    Sub Roll_Graph_Data()
    '
    ' Range_Test Macro
    
        Dim LC As Integer
        LC = Cells(2, Columns.Count).End(xlToLeft).Column
        
        Range("K5:VLC").Select
        Selection.Copy
        Range("L5").Select
        ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
            IconFileName:=False
        Sheets("Control").Select
    End Sub
    Last edited by Leith Ross; 05-14-2013 at 11:38 AM.

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,879

    Re: Adaptive cell range

    Hey!!

    This line is wrong!

    Range("K5:VLC").Select
    What Range do you exactly want?

    Thank You,

    Deep

  5. #5
    Forum Contributor
    Join Date
    10-16-2012
    Location
    Brooklyn
    MS-Off Ver
    Excel 2010 PC
    Posts
    137

    Re: Adaptive cell range

    Hey Deep.

    This might help make my problem more clear.

    Thanks for your patience.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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