+ Reply to Thread
Results 1 to 2 of 2

Select variable data range for 2 columns

  1. #1
    Registered User
    Join Date
    04-14-2010
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    21

    Select variable data range for 2 columns

    Hello

    Yesterday I got some help with code so that my code for inserting a graph looked for the last line of data that previous bit of code identified and not from line 3677 as the attached code currently shows. This was when the first part of the code was only selecting 1 column but now I need to graph two columns. The first part of code now correctly select the two columns.

    So I recorded the macro for inserting the graph (after running the macro to select the two columns) and for that workbook it works fine and graphs correctly column E and P data just as I want. The problem is that recording the insert graph macro on that workbook puts in 3677 lines of data in the code. If I run the macro in another workbook that only has say 2000 lines of data the 3677 number is still used by the code.

    what code do I need to replace the two references of 3677 in the graph code so that it always selects the last line of data that the first part of the macro code has selected?
    Please Login or Register  to view this content.
    thanks DOMINIC

  2. #2
    Forum Expert JasperD's Avatar
    Join Date
    05-07-2013
    Location
    Netherlands
    MS-Off Ver
    Excel 2016
    Posts
    1,393

    Re: Select variable data range for 2 columns

    Surprising you got so many views and no reply, cause the answer is already there in your code...

    the "lr = Worksheets("Sheet1").Cells(Rows.Count, "P").End(xlUp).Row" finds the last row of data in column "P" (hence lr).
    So instead of making direct references to 3677, it should refer to lr.

    For this to work, generally change codes where ranges are specifically mentioned as follows.
    Example (before)
    Please Login or Register  to view this content.
    Example (after)
    Please Login or Register  to view this content.
    (you can actually lose the '$' as well and clear up your code)

    In your code, it's changing the occurrences of "$3677" to " & lr"
    Please Login or Register  to view this content.
    Please click the * below if this helps
    Please click the * below if this helps

+ 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] Select updated data from a range of columns
    By Alylia in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 PM
  2. Select updated data from a range of columns
    By Alylia in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 11:05 AM
  3. [SOLVED] Select updated data from a range of columns
    By Alylia in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  4. Select updated data from a range of columns
    By Alylia in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 07:05 AM
  5. [SOLVED] Select updated data from a range of columns
    By Alylia in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 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