-
OK,
So i started playing round with mdmackillop's code and have come up with, what seems to be, very stable code.....touch wood.
I created a Forms scroll bar and linked that to a hidden cell on my page - rather than creating code to use under scrolbar1_change()
This is what I came up with:
[vba]Sub ListBox1_Change()
If RunList = True Then
Dim tmp As Long, Rw As Long, scrl As Long
Dim StaffMember As String, ChrtRng As String, Chrt2Rng As String
Dim StartDate As Date
Dim StartCol As Long
Dim StartLetter As String
Dim EndLetter As String
'Hidden Linked Cell
scrl = Sheets("Reports").Range("L17").Value
'Change week ending dates
If scrl = 0 Then
StartDate = Date + 6 - Weekday(Date)
Else
StartDate = Date + 6 - Weekday(Date) + (scrl * 7)
End If
StartCol = Application.Match(CLng(StartDate), Worksheets("Fee Earning Stats").Rows(5), 0)
StartLetter = ColumnLetter(StartCol)
If StartCol >= 30 Then
EndLetter = ColumnLetter(35)
Else
EndLetter = ColumnLetter(StartCol + 5)
End If
tmp = ListBox1.ListIndex
With ListBox1
StaffMember = .List(tmp, 1) & " " & .List(tmp, 0)
End With
On Error Resume Next
Rw = Sheets("Fee Earning Stats").Columns(2).Find(StaffMember).Row
If Rw = 0 Then
MsgBox "Staff member has no current data"
Exit Sub
End If
ChrtRng = "$" & StartLetter & "$" & Rw & ":$" & EndLetter & "$" & Rw
ActiveSheet.ChartObjects("Chart 77").Select
ActiveChart.SeriesCollection(2).Formula = _
"=SERIES(""Non Fee Earning"",'Fee Earning Stats'!$" & StartLetter & "$5:$" & EndLetter & _
"$5,'Non Fee Earning Stats'!" & ChrtRng & ",2)"
ActiveChart.SeriesCollection(1).Formula = _
"=SERIES(""Fee Earning"",'Fee Earning Stats'!$" & StartLetter & "$5:$" & EndLetter & _
"$5,'Fee Earning Stats'!" & ChrtRng & ",1)"
End If
ListBox1.Activate
End Sub[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules