-2

I have a table of process measurements. Rows are measurements and columns are different variables. I have a macro that copies the data from another worksheet. The number on measurements can vary, and I'd like to write a macro that automatically selects range based on the number on measurements and plots the variable values as a function of time. I'd also like to have a macro that moves the source column of the chart one to the right, so every time that I run the macro, it plots different variable as a function of time(measurement). How should I approach this problem? Thank you.

1
  • Welcome to the site! Check out the tour and the how-to-ask page for more about asking questions that will attract quality answers. You can edit your question to include more information.
    – cxw
    Jun 27, 2018 at 19:06

1 Answer 1

0
  1. Put your data in one sheet
  2. Then use rngSourceData = Sheets(index).UsedRange to get the data automatically.
  3. Draw your chart by VBA codes. The chart creation normally need the source data range as input, then pass the rngSourceData to the function. Such as below demo:

    Set PTCache = ActiveWorkbook.PivotCaches.Create( _
        SourceType:=xlDatabase, _
        SourceData:=rngSourceData, _
        Version:=xlPivotTableVersion14)
    
  4. Then you can rerun the step 2-3 and refresh the chart if your data changed.

You may record the macro codes to get the example on how to create your specific chart then change the codes a little bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.