Results 1 to 6 of 6

Graph non-adjacent column data

Threaded View

  1. #1
    Registered User
    Join Date
    08-27-2010
    Location
    Maine
    MS-Off Ver
    Excel 2007
    Posts
    6

    Graph non-adjacent column data

    I'm trying to generate a line graph using VBA that selects data from alternating columns. I've included a spreadsheet that contains data for staff allocation (Forecast and Actual) over time.

    I'd like to be able to create a graph that plots just the forecast columns for the following rows:
    "Total Staff"
    "Total Allocation"
    "Remaining availability"

    Alternatively, I'd like to create a graph that plots a comparison of Forecast vs Actual rows:
    "Total Staff"
    "Total Allocation" and
    "Remaining availability".

    I'm having difficulties with understanding how to set the correct range.

    I'm using the following code but it's throwing an error:

    Sub linegraph()
    '
    ' linegraph Macro
    
    '
    
     Dim AltRng As Range
      Dim LastCol As Variant
      Dim Rng As Range
      Dim RngEnd As Range
      Dim Wks As Worksheet
      
       Set Wks = ActiveSheet
        LastCol = Wks.Cells.Find("*", , xlValues, xlWhole, xlByColumns, xlPrevious, False).Column
    
        'column 5 starting point for forecast data
    
          For C = 5 To LastCol Step 2
            Set Rng = Wks.Columns(C)
              If AltRng Is Nothing Then Set AltRng = Rng
              Set AltRng = Union(AltRng, Rng)
          Next C
          
      
       With ActiveSheet.ChartObjects.Add _
                (Left:=100, Width:=375, Top:=75, Height:=225)
             .Chart.SetSourceData Source:=Sheets("Sheet1").Range(AltRng)
            .Chart.ChartType = xlXYScatterLines
        End With
    
    
    End Sub
    thank you for your help
    Attached Files Attached Files
    Last edited by mgia0055; 08-27-2010 at 02:54 PM. Reason: Adding Code Tags

Thread Information

Users Browsing this Thread

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

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