Macro not Creating Pivot Table anymore

bobbysmith

New Member
Joined
Jan 24, 2015
Messages
29
I have a Excel Template, the workbook has sheets named "Data " and "Pivot". The data I pull comes from a CSV file which i open as excel file which i copy and paste to the "DATA" sheet Column N. When i execute the macro it formats it the way i want it and dumps the pivottable to the "Pivot" sheet. Recently the macro formats it the way i want it BUT...it is not creating the Pivot table. I tried testing with the data i pulled from the past weeks and it works but it is not working for current week. I think it has to do with data in the CSV file. Below is the Code and Data. Any insight would be greatly appreciated.

Code:
Sub FormatData()
'Offline Activities Report
Dim lnglastrow As Long
Application.ScreenUpdating = False
lnglastrow = ThisWorkbook.Worksheets("Data").Range("n" & Rows.Count).End(xlUp).Row

Range("o1:eek:" & lnglastrow).Copy
Range("a1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Range("p1:p" & lnglastrow).Copy
Range("b1").PasteSpecial xlPasteValues
Range("s1:s" & lnglastrow).Copy
Range("c1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Range("w1:w" & lnglastrow).Copy
Range("d1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Range("d2:d" & lnglastrow).NumberFormat = "m/d/yyyy"
Range("y1:ac" & lnglastrow).Copy
Range("e1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Range("ae1:af" & lnglastrow).Copy
Range("j1").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Range("l1").Select
Range("f2:g" & lnglastrow).NumberFormat = "h:mm"
Range("j1").Value = "Dept"
Range("k1").Value = "Site/Dept"
Range("a1:k1").HorizontalAlignment = xlCenter
Range("a1:a" & lnglastrow).RowHeight = 15
Range("a1:k1").Font.Bold = True

With ThisWorkbook.Worksheets("Data").Range("j1:j" & lnglastrow)
.Replace what:="WAU", replacement:="", lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False
.Replace what:="CED", replacement:="", lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False
.Replace what:="TUL", replacement:="", lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False
.Replace what:="KNX", replacement:="", lookat:=xlPart, searchorder:=xlByRows, MatchCase:=False
End With

Range("a1:k1").AutoFilter
Range("a:k").Sort key1:=Range("f1"), order1:=xlAscending, Header:=xlYes
Range("a:h").EntireColumn.AutoFit
Range("j:k").EntireColumn.AutoFit
Range("a2").Select
ActiveWindow.FreezePanes = True
Range("N:AL").EntireColumn.ClearContents
Range("n1").Select
Sheets("Data").Buttons("button 1").Visible = False
Sheets("Data").Buttons("button 2").Visible = False

Range("n1").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With

Range("n1").ClearComments
Range("l1").Select

Range("m1").Value = "Team meeting Ct"
Range("f2:f" & lnglastrow).Copy
Range("m2").PasteSpecial xlPasteAll
Application.CutCopyMode = False
Range("m1").Font.Bold = True

Dim lnglastrow2 As Long
lnglastrow2 = ThisWorkbook.Worksheets("Data").Range("m" & Rows.Count).End(xlUp).Row
Range("m1:m" & lnglastrow2).RemoveDuplicates Columns:=Array(1), Header:=xlYes

Dim lnglastrow3 As Long
lnglastrow3 = ThisWorkbook.Worksheets("Data").Range("m" & Rows.Count).End(xlUp).Row
Range("n1").Value = " BUS SUPPT"
Range("o1").Value = " CUST SERV"
Range("p1").Value = " CUSTSERV HELP QUEUE"
Range("q1").Value = " CUSTSERV MULTI"
Range("r1").Value = " SOLUTIONS CONSULTANTS"
Range("s1").Value = " TECH SUPPT"
Range("t1").Value = " TELESALES"
Range("u1").Value = " WNP"
Range("n1:u1").Font.Bold = True

Range("n2").Formula = "=countifs($e:$e,""Team"",$j:$j,n$1,$f:$f,$m2)"
Range("n2").AutoFill Range("n2:u2"), xlFillDefault
Range("n2:u2").AutoFill Range("n2:u" & lnglastrow3), xlFillDefault

Range("n2:u" & lnglastrow3).Copy
Range("n2").PasteSpecial xlPasteValues
Application.CutCopyMode = False
Range("l1").Select


Range("n2:u" & lnglastrow3).FormatConditions.Add xlCellValue, xlGreater, "=0"
Range("n2:u" & lnglastrow3).FormatConditions(Range("n2:u" & lnglastrow3).FormatConditions.Count). _
SetFirstPriority
With Range("n2:u" & lnglastrow3).FormatConditions(1).Font
.Bold = True
.Color = vbRed
.TintAndShade = 0
End With

Range("m:u").EntireColumn.AutoFit
Range("n2:u" & lnglastrow3).HorizontalAlignment = xlCenter
Range("l1").Select

Dim pvtC As PivotCache
Dim pvt As PivotTable
Dim pvtF As PivotField

On Error Resume Next
ThisWorkbook.Worksheets("Pivot").Select
ActiveSheet.PivotTables("pivottable1").TableRange2.Clear

ThisWorkbook.Worksheets("Data").Select
Set pvtC = ActiveWorkbook.PivotCaches.Create(xlDatabase, Range("a1:k" & lnglastrow))
Sheets("Pivot").Select
Set pvt = ActiveSheet.PivotTables.Add(pvtC, Range("a1"), "pivottable1")
With pvt

.PivotFields("Start_Date").Orientation = xlPageField
.PivotFields("Nom_Date").Orientation = xlPageField
.PivotFields("Dept").Orientation = xlRowField
.PivotFields("Seg_Code").Orientation = xlColumnField
.PivotFields("Emp_Sk").Orientation = xlDataField
.PivotFields("Sum of Emp_Sk").Function = xlCount
.DataBodyRange.NumberFormat = "#,0"
.ColumnGrand = False
.RowGrand = False
.CompactLayoutColumnHeader = "Offline"
.CompactLayoutRowHeader = "Offline Activities by Dept"
.ShowTableStyleRowStripes = True
.TableStyle2 = "pivotstylelight22"
.PivotFields("Offline Activities by Dept").AutoSort Order:=xlAscending
End With

Range("a3").EntireRow.Hidden = True
ActiveWorkbook.ShowPivotTableFieldList = False
Application.ScreenUpdating = True

End Sub

DATA: Columns (A:S)
PRI_INDEXEMP_SKEMP_IDEMP_LAST_NAMEEMP_FIRST_NAMEEMP_SORT_NAMEEMP_SHORT_NAMEEMP_SENIORITYEMP_EFF_HIRE_DATENOM_DATESTART_DATESEG_CODESTART_MOMENTSTOP_MOMENTDURATIONMEMORANKEMP_CLASS_1EMP_CLASS_1_DESCR
433-9.9E+111DOE1JOEDOE1,JOEDOE1, JOE20060619########8/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
437-9.9E+112DOE2JOEDOE2,JOEDOE2, JOE200801071/7/20088/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
253-9.9E+113DOE3JOEDOE3,JOEDOE3, JOE20170313########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
439-9.9E+114DOE4JOEDOE4,JOEDOE4, JOE20090622########8/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
166-9.6E+115DOE5JOEDOE5,JOEDOE5, JOE20130930########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54KNX CUST SERVKNX CUST SERV
443-9.6E+116DOE6JOEDOE6,JOEDOE6, JOE20140310########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL TELESALESTUL TELESALES
446-9.6E+117DOE7JOEDOE7,JOEDOE7, JOE20160815########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL TELESALESTUL TELESALES
466-9.6E+118DOE8JOEDOE8,JOEDOE8, JOE201407077/7/20148/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54WAU CUSTSERV MULTIWAU CUSTSERV MULTI
447-9.6E+119DOE9JOEDOE9,JOEDOE9, JOE20140915########8/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
374-9.6E+1110DOE10JOEDOE10,JOEDOE10, JOE20140915########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54WAU CUST SERVWAU CUST SERV
468-9.6E+1111DOE11JOEDOE11,JOEDOE11, JOE20141124########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54WAU CUSTSERV MULTIWAU CUSTSERV MULTI
470-9.6E+1112DOE12JOEDOE12,JOEDOE12, JOE20150112########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54WAU CUSTSERV MULTIWAU CUSTSERV MULTI
450-9.6E+1113DOE13JOEDOE13,JOEDOE13, JOE20160815########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL TELESALESTUL TELESALES
452-9.6E+1114DOE14JOEDOE14,JOEDOE14, JOE20151005########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL TELESALESTUL TELESALES
454-9.6E+1115DOE15JOEDOE15,JOEDOE15, JOE20121217########8/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
456-9.6E+1116DOE16JOEDOE16,JOEDOE16, JOE20160523########8/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
290-9.6E+1117DOE17JOEDOE17,JOEDOE17, JOE20160718########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
458-9.6E+1118DOE18JOEDOE18,JOEDOE18, JOE20160815########8/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
460-9.6E+1119DOE19JOEDOE19,JOEDOE19, JOE20160815########8/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
463-9.6E+1120DOE20JOEDOE20,JOEDOE20, JOE20160815########8/2/20178/2/2017CBT################10Tech 21

Steps to Complete Training

1. Go to Academy Point and click on the Register button in the top-right corner.

2. Enter the requested information and the User Registration Code “USCellular1031”

3. Complete the modules listed under “My Training Plan.”



54TUL TELESALESTUL TELESALES
471-9.6E+1121DOE21JOEDOE21,JOEDOE21, JOE20160912########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54WAU CUSTSERV MULTIWAU CUSTSERV MULTI
176-9.6E+1122DOE22JOEDOE22,JOEDOE22, JOE20161031########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54KNX CUST SERVKNX CUST SERV
293-9.6E+1123DOE23JOEDOE23,JOEDOE23, JOE20160926########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
295-9.6E+1124DOE24JOEDOE24,JOEDOE24, JOE20160926########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
296-9.6E+1125DOE25JOEDOE25,JOEDOE25, JOE20160926########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
177-9.6E+1126DOE26JOEDOE26,JOEDOE26, JOE20161031########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54KNX CUST SERVKNX CUST SERV
308-9.6E+1127DOE27JOEDOE27,JOEDOE27, JOE20161205########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
313-9.6E+1128DOE28JOEDOE28,JOEDOE28, JOE20170116########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
316-9.6E+1129DOE29JOEDOE29,JOEDOE29, JOE20170116########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
321-9.6E+1130DOE30JOEDOE30,JOEDOE30, JOE20170313########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
328-9.6E+1131DOE31JOEDOE31,JOEDOE31, JOE20170313########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
332-9.6E+1132DOE32JOEDOE32,JOEDOE32, JOE20170313########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54TUL CUST SERVTUL CUST SERV
180-9.6E+1133DOE33JOEDOE33,JOEDOE33, JOE20161107########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54KNX CUST SERVKNX CUST SERV
181-9.6E+1134DOE34JOEDOE34,JOEDOE34, JOE20170424########8/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54KNX CUST SERVKNX CUST SERV
413-9.6E+1135DOE35JOEDOE35,JOEDOE35, JOE201705085/8/20178/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54WAU CUST SERVWAU CUST SERV
419-9.6E+1136DOE36JOEDOE36,JOEDOE36, JOE201705085/8/20178/2/20178/2/2017CBT################10Go to tech21training and click Register in the top-right corner. Complete registration using for the User Registration Code. Sign-in when prompted and then scroll down and complete the 3 modules listed under My Training Plan.54WAU CUST SERVWAU CUST SERV

<colgroup><col span="3"><col><col span="2"><col><col><col span="3"><col><col span="3"><col><col span="3"></colgroup><tbody>
</tbody>
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,215,479
Messages
6,125,041
Members
449,206
Latest member
Healthydogs

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