Trouble Selecting Sheet in VBA

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)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Do you need to select it?

Code:
Sheets("Summer Graphs").ChartObjects("Chart 1").Chart.SeriesCollection(1).Border.Color = RGB(149, 179, 215)
 
Upvote 0

Forum statistics

Threads
1,224,552
Messages
6,179,486
Members
452,917
Latest member
MrsMSalt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top