I think this is best explained by the picture attached. In a nutshell, the code below is not finding my cells, thought they're obviously there. I tried replacing ".Value = "Stipend", with "Select" and the code still failed, but I don't understand why. Help would be highly appreciated.
.Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Value = "Stipend"
To be fair, I'll post the surrounding code in case there's something else that's messing it up.
Private Sub CommandButton1_Click()
'Have Excel get my Expenses
Dim PT As PivotTable
Dim PI As PivotItem
Dim lCalc As XlCalculation
Dim Wb As Workbook
Dim WbSrc As Workbook
Dim Ws As Worksheet
Dim MFRmo As String
With Application
.ScreenUpdating = False
.EnableEvents = False
.DisplayAlerts = False
lCalc = .Calculation
.Calculation = xlCalculationManual
.DisplayStatusBar = False
Set Wb = ThisWorkbook
Application.DisplayAlerts = False
On Error Resume Next
ThisWorkbook.Sheets("old_Current MFR").Delete
ThisWorkbook.Sheets("Total Current Expense").Delete
On Error GoTo 0
Application.DisplayAlerts = True
If IsEmpty(Wb.Sheets("Start Tab").Range("C2")) Then
MsgBox "You first have to select a month on the Start Tab"
Exit Sub
End If
If IsEmpty(Wb.Sheets("Start Tab").Range("C7")) Then
MsgBox "You first have to select your name on the Start Tab"
Exit Sub
End If
MFRmo = Wb.Sheets("Start Tab").Range("C2").Value
Set Ws = Wb.Sheets(MFRmo & " MFR")
Ws.Activate
Ws.Name = "old_Current MFR"
Ws.Visible = xlSheetHidden
'FY15 code
Set WbSrc = Workbooks.Open _
("\\12aust1001fs01\SHARE10011\Budget\SOBUDGET\_Protected_Data\Source_Docs\_OOE_MOF_PivotTables\OOE_BR1415_ExpDtl_NonFCAdopt.xlsx", ReadOnly:=True, UpdateLinks:=True)
Set PT = ActiveSheet.PivotTables("PivotTable1")
With PT
.ManualUpdate = True
'FY15 code
.PivotFields("BUDGET_REF").CurrentPage = "2015"
.PivotFields("STRATEGY").Orientation = xlPageField
With .PivotFields("BA")
.CurrentPage = Wb.Sheets("Start Tab").Range("C7").Value
.Orientation = xlPageField
.Position = 1
End With
On Error Resume Next
With PT.PivotFields("FY_AP")
.Orientation = xlPageField
.Position = 1
For i = 1 To .PivotItems.Count
If .PivotItems(i).Name Like "*GOB*" Or .PivotItems(i).Name Like "*LAR*" Then
.PivotItems(i).Visible = False
Else
.PivotItems(i).Visible = True
End If
Next i
End With
On Error GoTo 0
With PT.PivotFields("MOS2")
.Orientation = xlColumnField
.Position = 1
.PivotItems("BUDGET").Position = 1
End With
With PT.PivotFields("LBB_ACCT")
For Each PI In PT.PivotFields("LBB_ACCT").PivotItems
If PI = "FTEAFF" Or PI = "FTEATH" Or PI = "FTEHHSC" Or PI = "FTEABU" Or PI = "CP_Spread" Or PI = "L9999" Then
PI.Visible = False
Else
PI.Visible = True
End If
Next
End With
'Group the Funded FTEs together
.ColumnGrand = False
.RowGrand = False
.RepeatAllLabels xlRepeatLabels
.InGridDropZones = True
.RowAxisLayout xlTabularRow
' With .TableRange1
' .Offset(2, 0).Resize(.Rows.Count - 2, .Columns.Count).Copy wsFTE.Range("B3")
' End With
On Error Resume Next
For Each PF In PT.PivotFields
'First, set index 1 (Automatic) to True,
'so all other values are set to False
PF.Subtotals(1) = True
PF.Subtotals(1) = False
Next PF
On Error GoTo 0
'Let the PT update itself now
.ManualUpdate = False
End With
'Convert my pivot to values
PT.TableRange2.Select
Selection.Copy
With Selection
.PasteSpecial xlPasteValuesAndNumberFormats
.PasteSpecial xlPasteColumnWidths
End With
Application.CutCopyMode = False
Set PT = Nothing
'Move to our MFR Workbook.
ActiveSheet.Move after:=Wb.Sheets("Aug MFR")
ActiveSheet.Name = "Total Current Expense"
With ActiveSheet
'Determine our First row and delete what's above it
LastRow = .Range("D1").End(xlDown).Row
.Range("A1:Z" & LastRow).Delete
'create our categories
.Columns("C:C").Copy
.Columns("A:A").Insert Shift:=xlToRight
.Range("A1").Value = "Category"
Dim RepWhat(), RepWith()
RepWhat = Array("FTES", "FTEABF", "FTECAP", "L2005B", "L2005", "L2005M", "L1002", "L1001O", "L1001")
RepWith = Array("Filled/Projected", "Funded FTEs", "Funded FTEs", "L2005B-Out of State Travel", "L2005-In State Travel", "L2005M-In State Mileage", "Other Personnel", "Overtime", "Salary")
For i = LBound(RepWhat) To UBound(RepWhat)
.Columns("A").Replace What:=RepWhat(i), Replacement:=RepWith(i), _
LookAt:=xlPart, SearchOrder:=xlByRows
Next i
Stop
'Isolate our Stipend
.Range("A1").AutoFilter Field:=3, Criteria1:="=11003"
.Range("A1").AutoFilter Field:=4, Criteria1:="=L2009"
.Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).Value = "Stipend"
.AutoFilterMode = False
'insert a column for Type
.Columns(1).Insert
.Range("A1").Value = "Cost Per?"
.Range("A2:A" & LastRow).FormulaR1C1 = "=IF(LEFT(RC[1],1) = ""L"",""Lbb Acct"",""Cost Per"")"
'insert a column for Lookup
.Columns(1).Insert
.Range("A1").Value = "Lookup"
.Range("A2:A" & LastRow).FormulaR1C1 = "=RC[1]&RC[2]&RC[3]&RC[4]&RC[5]"
.Columns.AutoFit
End With
'Copy it and make it our MFR Projection template
ActiveSheet.Copy after:=Sheets("Start Tab")
Set Ws = ActiveSheet
Ws.Name = MFRmo & " MFR"
'Now let's start slicing and dicing
'Determine our ranges for Expense (include the MFR month), Projections, Budget
Range("AX1:AX25").Name = "RMEX_DET"
.DisplayStatusBar = True
.EnableEvents = True
.Calculation = lCalc
.ScreenUpdating = True
End With
End Sub
Bookmarks