+ Reply to Thread
Results 1 to 5 of 5

How to make the following code dynamic?

  1. #1
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220

    How to make the following code dynamic?

    Hi,
    I have a macro that extracts data from a large table based on some criteria.

    After the macro extracts the pertinent data, it needs to be sorted based on three different columns.

    Clicking "Record MAcro" compiles the following code:

    Please Login or Register  to view this content.
    In the code above, the table size is "A6:P253". Row 6 is the table header, and row 253 happened to be the last row that contained data.

    In the code above, I would like to be able to replace all of the "253's" with a dynamic value based on the last row containing data.

    Anyone know how I can do that?
    Last edited by Rerock; 11-19-2015 at 03:33 PM.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: How to make the following code dynamic?

    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    01-21-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    227

    Re: How to make the following code dynamic?

    Try this:-

    in the beginning of your code add these to calculate Last row in the sheet.
    With ActiveSheet.UsedRange
    lrow = .Rows(.Rows.Count).Row
    End With

    and then replace all the Range() accordingly; Im doing it for the first range here(Range("A6:P253").Select), lrow below is dynamic

    Range(Cells(6,"A"),Cells(lrow,"P")).select
    If I've been of help, plz add reputation.

  4. #4
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220

    Re: How to make the following code dynamic?

    Thanks you Mr Davis; that worked like a charm!

    sakmsb, thanks for the confirmation; as you can see that's essentially what Mr. Davis posted as well.

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: How to make the following code dynamic?

    You're welcome. Glad to help out and thanks for the feedback.

+ 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] Format cell via code and make formatting dynamic
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 01-23-2015, 02:10 PM
  2. Simply VBA code and make it dynamic
    By Rusty315 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2014, 02:49 AM
  3. [SOLVED] Make print area dynamic & replace a SUMPRODUCT with code!
    By apla in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-20-2013, 10:04 AM
  4. I Want to know how I can make this formula into vba code for dynamic cell address
    By dgdgdg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-06-2013, 02:41 PM
  5. [SOLVED] I Want to know how I can make this formula into vba code for dynamic cell address
    By dgdgdg in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-06-2013, 12:54 PM
  6. [SOLVED] Make Static code Dynamic
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2012, 11:09 AM
  7. Make dynamic charts more dynamic
    By Milo in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 04-12-2006, 04:10 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