How to Calculate One-Minute Average Pressure in Excel with VBA
Question details
The user needs a method to calculate one-minute average pressure from data recorded every second using Excel VBA, as an alternative to using a PivotTable.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Processing large datasets of per-second pressure readings to automatically calculate and record 60-second block averages.
- Observed behavior
- The user wants to group 60 rows of data at a time, calculate the average for each group, and output the result in an adjacent column.
Ensure your pressure readings are listed continuously without blank rows starting from column B, and verify that macros are enabled in your Excel or WPS Office workbook.
Calculate Block Averages Using a Custom VBA Macro
Use a VBA script to automatically loop through groups of 60 rows, calculate the average for each block, and print the result in the adjacent column.
This procedure assumes your pressure data is in column B with a header in B1. It shifts down 60 rows at a time, calculates the average of those 60 cells, and places the result on the 60th row in column C.
Press Alt + F11 on your keyboard to open the Visual Basic for Applications (VBA) editor in Excel.
Click 'Insert' from the top menu and select 'Module' to create a new blank script window.
Copy and paste the following code into the module window: Sub Calculate_Average_Pressure_per_minute() Dim header As Range Dim pressureRng As Range With ActiveSheet Set header = .Range("B1") Set pressureRng = header.Offset(1).Resize(60, 1) Do pressureRng.Cells(pressureRng.Cells.Count, 1).Offset(0, 1).Value = Application.WorksheetFunction.Average(pressureRng) Set pressureRng = pressureRng.Offset(60) Loop Until Application.WorksheetFunction.Count(pressureRng) < 60 End With MsgBox "Job Done" End Sub
Close the VBA editor. In your worksheet, press Alt + F8, select 'Calculate_Average_Pressure_per_minute' from the Macro dialog box, and click 'Run'.

Easily Run VBA Macros for Data Averages in WPS Office
WPS Spreadsheet provides comprehensive support for VBA and Macros, allowing you to run custom scripts like the 60-second average calculator seamlessly and efficiently.
- 1. Enable Macros in WPS: Open your workbook in WPS Spreadsheet and ensure the Developer Tools are enabled by navigating to Options > Customize Ribbon.
- 2. Access the VBA Editor: Navigate to the 'Developer' tab on the ribbon and click 'Visual Basic', or simply press Alt + F11.
- 3. Execute the Code: Insert a new module, paste the average calculation code, and run it to instantly process your per-second readings.

Frequently Asked Questions
Can I use this VBA code if my data is not in column B?
Yes. You just need to change the line 'Set header = .Range("B1")' to match the starting cell of your data column, such as 'A1' or 'C1'.
What happens if my data doesn't divide exactly into 60 rows?
The provided loop condition 'Loop Until Application.WorksheetFunction.Count(pressureRng) < 60' stops processing when the remaining block has fewer than 60 numeric values. The remainder data will simply be ignored.
Why is the average placed at the bottom of the 60-row block?
The code uses an offset targeting the 60th cell in the block to place the average adjacent to the end of the minute. If you prefer it at the top of the block, you can modify the offset reference from 'pressureRng.Cells.Count' to '1'.
Is there a way to calculate the average without VBA?
Yes, you can alternatively use an Excel PivotTable by grouping the time data by minutes, or use a combination of the AVERAGE and OFFSET functions combined with ROW() calculations in standard formulas.




