Hi all-
Am pretty new to VBA and hoping to get some assistance from the experts. I have a worksheet with a large range of data. From the worksheet, I am able to create a pivot table using code. For the row, there is one field and for the values, I am using the count option. For the row, the data is in seconds and for the value, it gives me the count of instances for the number of seconds. What I want to do is the following: in the adjacent colum next the the values, I want to convert seconds to the following format: h:mm:ss by dividing the number of seconds by 86400 and convert the format to h:mm:ss. I want the formula to run on the entire data set in the pivot table. Here is the code I came up with..
'Insert Data Field
With ActiveSheet.PivotTables("SalesPivotTable").PivotFields("2. ACE requests Lock and Confirm Eligibility, per Throttle Rate")
.Orientation = xlDataField
.Position = 1
.Function = xlCount
.NumberFormat = "#,##0"
.Name = "BAN Count "
End With
Set rng = Range("D3:D1000")
For Each cell In rng
Range("D3").Select
ActiveCell.Formula = "=B3/86400"
Selection.NumberFormat = "[h]:mm:ss;@"
Next cell
As you can see, I can't figure out how to move to the next cell and convert seconds to time format. Attached is a pic of my pivot table. Again, hoping one of the experts can assist. Thanks for the help
Am pretty new to VBA and hoping to get some assistance from the experts. I have a worksheet with a large range of data. From the worksheet, I am able to create a pivot table using code. For the row, there is one field and for the values, I am using the count option. For the row, the data is in seconds and for the value, it gives me the count of instances for the number of seconds. What I want to do is the following: in the adjacent colum next the the values, I want to convert seconds to the following format: h:mm:ss by dividing the number of seconds by 86400 and convert the format to h:mm:ss. I want the formula to run on the entire data set in the pivot table. Here is the code I came up with..
Code:
'Insert Data Field
With ActiveSheet.PivotTables("SalesPivotTable").PivotFields("2. ACE requests Lock and Confirm Eligibility, per Throttle Rate")
.Orientation = xlDataField
.Position = 1
.Function = xlCount
.NumberFormat = "#,##0"
.Name = "BAN Count "
End With
Set rng = Range("D3:D1000")
For Each cell In rng
Range("D3").Select
ActiveCell.Formula = "=B3/86400"
Selection.NumberFormat = "[h]:mm:ss;@"
Next cell
Code:
As you can see, I can't figure out how to move to the next cell and convert seconds to time format. Attached is a pic of my pivot table. Again, hoping one of the experts can assist. Thanks for the help