I’ve created a few macros to analyze rain data from an airport. The macros work fine when I type them manually into each cell.
When I copy the macros down the columns, the new rows correctly populate with the macro formula and reference cells. However, what displays and is set as the value for the cell is the value from the first cell that I copied the formula down from.
For example, C5 has the formula: “=twoday(B5)” and has a value of 0.2. When copied down, I want C6, C7, etc. to show “=twoday(B6)”, “=twoday(B7)”, etc. And, they do, but they also show the value 0.2, but should show a different value. When I click the cell then the formula bar and hit enter, it correctly shows the value I want.
Rather than hitting enter on 4000 cells, how can I correctly copy the macros down columns? I've tried checking the calculation settings for automatic/manual (and using F9), and tried both to no avail. Anything else I can try?
Here is the code:
Public Function twoday(rain_current_day)
'Allow x to be the range of cells that we check for the rain data
'Offset = row, column
Dim x As Range
Set x = Range(ActiveCell.Offset(-1, -1), ActiveCell.Offset(, -1)) 'adjacent
cell (left) and 1 cell up (2 data points total)
'find out if any of the important rows are blank or text data
If IsNumeric(x.Cells(1, 1)) And Not IsEmpty(x.Cells(1, 1)) Then
twoday = WorksheetFunction.Sum(x)
Else
twoday = ""
End If
End Function