elotromateo
New Member
- Joined
- May 19, 2010
- Messages
- 42
I have some code in VBA that is having problems selecting a sheet. I have a With statement for one sheet, select that first, do some code, and then attempt to switch to another sheet with charts. Unfortunately, it refuses to move from the first sheet. It used to work and I've been over the code and there doesn't seem to be a problem, but it still doesn't work.
Code:
Sub UpdateSumGraphs()
Dim Cell1, Cell2, Cell3, Cell4, Cell5, Cell6, Cell7, Cell8
Dim Row1 As Long, Row2 As Long, Row3 As Long, Row4 As Long, Row5 As Long, Row6 As Long, Row7 As Long, Row8 As Long
Dim LastRow As Long
Dim Bldg As String
Dim YrB, YrC
Dim Yint As Double
Application.ScreenUpdating = False
With Sheets("Graphs")
Bldg = .Range("K1")
YrB = .Range("K2")
YrC = .Range("K4")
End With
With Sheets("Data")
.Select
.Calculate
LastRow = Range("B" & Rows.Count).End(xlUp).Row
Cell5 = Range("A1")
Cell6 = Range("A" & LastRow)
For m = 1 To LastRow Step 1
If Cell5 = Bldg Then
Exit For
End If
Cell5 = Range("A" & m + 1)
Next
For n = LastRow To 2 Step -1
If Cell6 = Bldg Then
Exit For
End If
Cell6 = Range("A" & n - 1)
Next
Row5 = m
Row6 = n
'Similar Code
Sheets("Summer Graphs").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Border.Color = RGB(149, 179, 215)