After I use the macro recorder to set the two columns to text and add a pivot table refresh, it gives me run-time error '1004'. :
Run-time error '1004':
We can't make this change for the selected cells because it will affect a PivotTable. Use the field list to change the report. If you are trying to insert or delete cells, move the PivotTable and try again.
The error is after I try to run it.
This is the code:
Sub Practice_1()
'
' Practice_1 Macro
'
'
Columns("A:A").Select
Application.CutCopyMode = False
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Columns("E:E").Select
Selection.TextToColumns Destination:=Range("E1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 1), TrailingMinusNumbers:=True
Sheets("NS Level").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
Sheets("CO Level").Select
ActiveSheet.PivotTables("PivotTable1").PivotCache.Refresh
End Sub
I've also tried this code but it prompts you to manually select the cells and I want it to just run for both column A and E.
Sub RemoveLeadingZero()
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Select one Range that you want to remove leading zero:", "RemoveLeadingZero", WorkRng.Address, Type:=8)
WorkRng.NumberFormat = "General"
WorkRng.Value = WorkRng.Value
End Sub