Charts overlapping datatable on spreadsheet.

I'm now having a problem where the graphs on a spreadsheet are now overlapping the datatable.  I'm creating the spreadsheet from within access using vba.  I thought the following code was working fine but now I see that it really wasn't.  I'm trying to offset the top parameter of each chart so they line up below the used range of the datatable.

Sub LineUpMyCharts(objWS As Object)
    ' Comments:
    ' Params  : objWS
    ' Modified:
    
    On Error GoTo PROC_ERR
    
    Dim objXlSheet As Object
    Dim objChart As Object
    Dim sngMyHeight As Single
    Dim sngMywidth As Single
    Dim lngChartCount As Long
    Dim lngChartIndex As Long
    
    sngMywidth = 750
    sngMyHeight = 300
    
    Set objXlSheet = objWS
    
    lngChartCount = objWS.ChartObjects.Count
    
    For lngChartIndex = 1 To lngChartCount
        Set objChart = objXlSheet.ChartObjects(lngChartIndex)
        With objChart
            .Top = objXlSheet.UsedRange.Rows.Count + ((sngMyHeight + 50) * lngChartIndex)
        End With
    Next
    
PROC_EXIT:
    Exit Sub
    
PROC_ERR:
    MsgBox Err.Number & vbTab & Err.Description, vbCritical, Me.Name & ".LineUpMyCharts"
    Resume PROC_EXIT
    
End Sub

Open in new window

Juan VelasquezAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rey Obrero (Capricorn1)Commented:
<I'm trying to offset the top parameter of each chart so they line up below the used range of the datatable.>

to position the chart below the datatable, you need to get the address of the cell after the datatable

assuming this code
objXlSheet.UsedRange.Rows.Count
           gives you a value of 10

create a variable, Dim chartRange as range
set chartRange=activesheet.range("A11")

        With objChart
            .Top = chartRange.top
        End With

get the idea?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Juan VelasquezAuthor Commented:
Thanks again
0
Juan VelasquezAuthor Commented:
Hello Rey,

Below is my final code, where I implemented your solution.  Now I can line up vertically any number of charts. Thanks again for your help.

Sub LineUpMyCharts(objWS As Object)
    ' Comments:
    ' Params  : objWS
    ' Modified:
    
    On Error GoTo PROC_ERR
    
    Dim objXlSheet As Object
    Dim objChart As Object
    Dim sngMyHeight As Single
    Dim sngMywidth As Single
    Dim lngChartCount As Long
    Dim lngChartIndex As Long
    Dim chartRange As Object
    Dim lngRowCount
    
    
    sngMywidth = 750
    sngMyHeight = 300
    
    Set objXlSheet = objWS
    lngRowCount = objXlSheet.UsedRange.Rows.Count + 1
    Set chartRange = objXlSheet.range("A" & lngRowCount)
    
    lngChartCount = objWS.ChartObjects.Count
    
    For lngChartIndex = 1 To lngChartCount
        Set objChart = objXlSheet.ChartObjects(lngChartIndex)
        With objChart
            If lngChartIndex = 1 Then               
                .Top = chartRange.Top + 50
            Else
                .Top = chartRange.Top + 50 + ((sngMyHeight + 50) * (lngChartIndex - 1))
            End If
        End With
    Next
    
PROC_EXIT:
    Exit Sub
    
PROC_ERR:
    MsgBox Err.Number & vbTab & Err.Description, vbCritical, Me.Name & ".LineUpMyCharts"
    Resume PROC_EXIT
    
End Sub

Open in new window

0
Rey Obrero (Capricorn1)Commented:
cool
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.