ErinKSimmons
New Member
- Joined
- Oct 9, 2019
- Messages
- 9
I have a selection change macro in a file that updates only when the selection occurs in the "NIIN" column of values. The macro works fine unless you apply a filter (from the preapplied AutoFilter) that hides the row that is currently being graphed and even if I select a now visible cell it continues to error.
I have tried to handle it by selecting F11 in the gray and then moving down to the first visible row, but that isn't the answer.
Any help is appreciated. Also if there is a better way to achieve updating a graph of one row based on the currently selected row, I am open to ideas.
I have tried to handle it by selecting F11 in the gray and then moving down to the first visible row, but that isn't the answer.
Any help is appreciated. Also if there is a better way to achieve updating a graph of one row based on the currently selected row, I am open to ideas.
Code:
Private Sub Worksheet_SelectionChange(ByVal NIINSelected As Range)
On Error GoTo ErrorHandler
' The variable NIINCells contains the cells that will
' cause graph to update
'Find the last non-blank cell in column F(6)
Dim LastRow As Long
LastRow = Cells(Rows.Count, 6).End(xlUp).Row
Set NIINCells = Range("F12:F" & LastRow)
If NIINSelected.Count > 1 Then
Exit Sub
End If
If Not Application.Intersect(NIINCells, Range(NIINSelected.Address)) _
Is Nothing Then
Dim NIINRow As Long
NIINRow = NIINSelected.Row
ActiveSheet.ChartObjects("NIINDmdChart").Activate
ActiveChart.FullSeriesCollection(1).Values = NIINSelected.Offset(0, 18).Resize(1, 3)
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = NIINSelected.Value & " - " & NIINSelected.Offset(0, 4).Value & " Demand"
NIINSelected.Select
End If
Exit Sub
ErrorHandler:
Range("F11").Select
ActiveCell.Offset(1, 0).Select
Do Until ActiveCell.EntireRow.Hidden = False
ActiveCell.Offset(1, 0).Select
Loop
End Sub