VBA Help - Select Commands Not Working in Code???

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Not sure what is wrong with my code but it is erroring outon one line, I am not sure why the select command is not working?

My code
Code:
Option Explicit
'--------------------------------------------------------
'--- Updates ByCostCenter Sheet
'---------------------------------------------------------
Sub ByCostCenterCopyPast()
Dim lRow        As Long
Dim Sht         As Worksheet


Set Sht = Sheets("By Cost Center")
lRow = Sht.Cells(Rows.Count, 13).End(xlUp).Row  '13 refers to the row to start on
    
Application.DisplayAlerts = False
Application.ScreenUpdating = False
    
    TimeStamp
    
With Sheets("Query Results")
    .Visible = True
        .Range("AR1:AR9").Copy .Range("AS1:JG9")
Calculate
    .Range("AS1:JG9").Copy
        .Range("AS1:JG9").PasteSpecial Paste:=xlPasteValues
Calculate
    .Range("A12:AF12").Copy .Range("A13:AF10000")
         .Range("A13:AF10000").Copy
            .Range("A13:AF10000").PasteSpecial Paste:=xlPasteValues
    
    .Range("JS12:KA12").Copy .Range("JS13:KA10000")
Calculate
    .Range("JS13:KA10000").Copy
        .Range("JS13:KA10000").PasteSpecial Paste:=xlPasteValues
            .Visible = False
End With
    
Sheets("PARAMETERS").Range("V57:Y58").Copy
Sheets("By Cost Center").Range("A4:D5").PasteSpecial Paste:=xlPasteValues
Sheets("By Cost Center").Select
Range("F13").Select
    
With Sht 'Sheet By Cost Center
    .PivotTables("PivotTable3").PivotCache.Refresh '<-----------------Hidden Pivot Table in Column F on By Cost Center Tab--------------------
        .Range("$A$10:$CD$652").AutoFilter
            .Range("$A$10:$CD$652").AutoFilter Field:=5
                .Range("A12:E12").Copy
                    .Range("A13:E652").PasteSpecial Paste:=xlPasteFormulas
    .Range("G12:CD12").Copy
        .Range("G13:CD652").PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
                SkipBlanks:=False, Transpose:=False
    Calculate
    
    .Range("A13:E" & lRow & "").Copy
        .Range("A13:E" & lRow & "").PasteSpecial Paste:=xlPasteValues
   
   .Range("G13:CD" & lRow & "").Copy
        .Range("G13:CD" & lRow & "").PasteSpecial Paste:=xlPasteValues
            .Range("$A$10:$CD$652").AutoFilter Field:=5, Criteria1:="<>"
End With
    
    
Sheets("PARAMETERS").Range("AH59").Copy
    Sheets("Summary by Quarter").Range("B4").PasteSpecial Paste:=xlPasteValues
        
Sheets("PARAMETERS").Range("W57:X57").Copy
    Sheets("Summary").Range("B6:C6").PasteSpecial Paste:=xlPasteValues


Sheets("BPC Hierarchy by Cost Center").Activate


UpdateBPChierarchyReport 'Macro Call
    
Sheets("By Ter-Dep-BU-Cst-Com-Pft").Activate


By_Ter_BU_Dep_Flat_File 'Macro Call
    
Sheets("PARAMETERS").Range("v28").Select   'Line that has the errors-------------------------------------------------------------------------------
    
Application.DisplayAlerts = True
Application.ScreenUpdating = True
    
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Is the sheet named PARAMETERS the activesheet when that line is executed? It must be if you want to select a range on it.
 
Upvote 0
@JoeMo I was under the impression a line like "Sheets("PARAMETERS").Range("v28").Select " would take the user to that range? am I missing something? Would I simply add a "Sheets("Parameters").Activate to get the code to work?


Is the sheet named PARAMETERS the activesheet when that line is executed? It must be if you want to select a range on it.
 
Upvote 0
You need to use something like this:
Code:
Application.Goto Sheets("PARAMETERS").Range("v28")
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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