LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 325
Default VBA and Charts

Erik,

Not sure if I included this in my other postings, but here's the code to
reset the named ranges picked up by the chart, so they move to the top of the
range containing your week numbers. Make sure that if you have field headers
above your data ranges that there is at least one blank row separating them
from any other entries in your worksheet. This application was created as a
database, and as such, adheres to the rules for Excel databases.

Sub ResetHours()
'This macro resets the X Axis, Actual, Budget and Cumulative ranges in
the HOURS chart to start from the first
'row of the XAxisLabels range. It requests the number of weeks that are
required to be plotted
'and ensures that this would not exceed the length of the XAxisLabels
range.

SheetUnprotect
DefineXAxisDetails

Message = "Reset Hours Graph"
Title = "Reset Hours Graph"
DefaultSize = 10

NewSize = InputBox(Message, Title, DefaultSize)

If NewSize < 1 Then
Exit Sub
End If

If Not (IsNumeric(NewSize)) Then
Exit Sub
End If

ProposedHoursResetLastRow = Range("HeaderXAxis").Offset(1, 0).Row +
NewSize - 1

'MsgBox ("First row would be: " & Range("HeaderXAxis").Offset(1, 0).Row
& vbCrLf & _
"Last row would be: " & ProposedHoursResetLastRow & vbCrLf & _
"Last X axis label row is: " & LastXAxisLabelRow)

If Range("HeaderXAxis").Offset(1, 0).Row + NewSize LastXAxisLabelRow
Then
MsgBox ("You can't reset the chart to this number of rows, as the
last row plotted would be " & vbCrLf & _
"lower than the last row in the X-Axis!")
Exit Sub
End If

ActiveWorkbook.Names.Add Name:="Hours_XAxis",
RefersTo:=Range("HeaderXAxis").Offset(1, 0).Resize(NewSize, 1)
ActiveWorkbook.Names.Add Name:="Hours_Actual",
RefersTo:=Range("HeaderTotalHours").Offset(1, 0).Resize(NewSize, 1)
ActiveWorkbook.Names.Add Name:="Hours_Budget",
RefersTo:=Range("HeaderBudgetHours").Offset(1, 0).Resize(NewSize, 1)
ActiveWorkbook.Names.Add Name:="Hours_Cumulative",
RefersTo:=Range("HeaderCumulativeHours").Offset(1, 0).Resize(NewSize, 1)
SheetProtect
End Sub

-----------------------------------------------------------------------------------
I'll go home now - good luck!

Pete




"ErikLong" wrote:


Hey,

I have a spreadsheet containing charts that are linked to cell ranges
within the worksheet. (last four weeks of data).

Every week, we must go in and move the source forward one column
manually.

Is there any way of doing this in VBA. I tried recording a macro and
moving it, but it assigns the new range to a literal location of cells,
so it isn't repeatable.

Please help if you can.

Thanks,
Erik J. Long


--
ErikLong
------------------------------------------------------------------------
ErikLong's Profile: http://www.excelforum.com/member.php...o&userid=32627
View this thread: http://www.excelforum.com/showthread...hreadid=524318




 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
charts toolbar / charts disappeared Pro Charts and Charting in Excel 0 December 18th 09 01:31 AM
link excel charts to web pages and update charts automatically Signguy Charts and Charting in Excel 1 April 22nd 08 08:29 PM
Charts - How to have multiple charts share a legend. Sean Charts and Charting in Excel 2 November 20th 07 04:49 AM
interactive charts for stacked bar charts [email protected] Charts and Charting in Excel 4 December 28th 06 09:58 PM
Matching the colors Column Charts and Pie Charts RohanSewgobind Charts and Charting in Excel 3 April 21st 06 09:35 PM


All times are GMT +1. The time now is 06:16 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"