willyboy58
Technical User
I have created my pivot tables to my liking, but now I need to do some math on the cells. I need to count the number of cells in a row that have any number of hours in them. In other words, cells that are not null. I should end up with a number around 20 (# of work days in a month). This count will be in a column to the right of the Pivot table. When I try to write the following code (abbreviated for this message) to do the count, I am told that “Cannot enter a formula for an item or field name of a Pivot Table.” I have tried to copy the table without the headings, but that doesn’t work either. So how do I do math on the cells of a Pivot Table? TIA Bill
'count the number of days worked and place total into cell
Sub CountingDays()
Dim DaysCounted As Single
Range("A4".Select
While Not IsEmpty(ActiveCell)
With ActiveCell() 'start at A4
'following needed for each time loop goes around
.Offset(1, 0).Select
‘ MsgBox "should be at A5" use Msgbox to help me track 'flow of procedure
'code is shortened for this message. If I can get two of the cells to add, then I can get the rest
.Offset(0, 1).Formula = "=if(" & .Offset(0, 1).Address & ">=0,1," _
& .Offset(0, 1).Address & ""
.Offset(0, 2).Formula = "=if(" & .Offset(0, 2).Address & ">=0,1," _
& .Offset(0, 2).Address & ""
'the following is to sum the days and place the total in the last _
' column for each client
.Offset(0, 31).Formula = "=sum(" & .Offset(0, 1).Address & ":" _
& .Offset(0, 30).Address & ""
DaysCounted = .Offset(0, 31)
End With
Wend
End Sub
'count the number of days worked and place total into cell
Sub CountingDays()
Dim DaysCounted As Single
Range("A4".Select
While Not IsEmpty(ActiveCell)
With ActiveCell() 'start at A4
'following needed for each time loop goes around
.Offset(1, 0).Select
‘ MsgBox "should be at A5" use Msgbox to help me track 'flow of procedure
'code is shortened for this message. If I can get two of the cells to add, then I can get the rest
.Offset(0, 1).Formula = "=if(" & .Offset(0, 1).Address & ">=0,1," _
& .Offset(0, 1).Address & ""
.Offset(0, 2).Formula = "=if(" & .Offset(0, 2).Address & ">=0,1," _
& .Offset(0, 2).Address & ""
'the following is to sum the days and place the total in the last _
' column for each client
.Offset(0, 31).Formula = "=sum(" & .Offset(0, 1).Address & ":" _
& .Offset(0, 30).Address & ""
DaysCounted = .Offset(0, 31)
End With
Wend
End Sub