Run a Tukey HSD Test After Two-Way ANOVA in Excel
Question details
Determine how to perform Tukey HSD post-hoc comparisons after Excel's two-way ANOVA with replication, and whether a macro can do the test.

- Product
- Microsoft Excel Analysis ToolPak
- Device & OS
- not provided
- Scenario
- The user has run a two-way ANOVA with replication and wants to compare factor levels while accounting for multiple comparisons.
- Observed behavior
- Excel's Analysis ToolPak does not provide a built-in Tukey HSD post-hoc test for the two-way ANOVA results.
Keep the original observations and identify both factors and their levels; the ANOVA summary alone is not enough to reproduce the model in R. Check that the observations are independent and that a two-way ANOVA with replication is appropriate for the design.
Run Tukey HSD comparisons in R
Use R to refit the two-way ANOVA from the original observations and compare factor levels or factor-level combinations.
TukeyHSD uses the fitted model's residual error and adjusts for multiple pairwise comparisons. If the factors interact, interpret main-effect comparisons cautiously and consider simple-effect comparisons instead.
In Excel, create a table with one observation per row and columns named factorA, factorB, and response. Enter each observation's two factor levels and numeric response.
Select File > Save As and choose CSV as the file type. Save the table as anova_data.csv; CSV saves only the active sheet.
In R, run: d <- read.csv('anova_data.csv'); d$factorA <- factor(d$factorA); d$factorB <- factor(d$factorB); model <- aov(response ~ factorA * factorB, data = d); summary(model). Use the path to your CSV if it is not in R's working directory.
In the R console, run TukeyHSD(model, which = c('factorA', 'factorB')) for main-effect comparisons, or TukeyHSD(model, which = 'factorA:factorB') to compare factor-level combinations. Review the adjusted p-values and confidence intervals.
Compare simple effects when factors interact
Use estimated marginal means in R to compare levels of one factor separately at each level of the other factor.
Prepare ANOVA Data with WPS Spreadsheet
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface. Open compatible Excel files, organize observations into columns, and export a CSV for analysis in statistical software. It does not add Tukey HSD to Excel's Analysis ToolPak.

Frequently Asked Questions
Does Excel's Analysis ToolPak include Tukey HSD?
No. The Analysis ToolPak provides two-way ANOVA with replication but does not include a built-in Tukey HSD post-hoc test. Export the original observations and use R or another statistical tool.
Can a VBA macro run Tukey HSD after a two-way ANOVA?
A custom VBA macro is possible, but it must use the correct model residual mean square and degrees of freedom, account for the replication structure, and adjust for multiple comparisons. Excel does not provide such a macro as part of the Analysis ToolPak.
What should I compare if the two factors interact?
Consider comparing levels of one factor within each level of the other. In R, pairs(emmeans(model, ~ factorA | factorB), adjust = 'tukey') performs those comparisons for factorA.
Can I run the R analysis using only Excel's ANOVA summary?
The R workflow shown here requires the original observations to refit the model. Arrange them in factorA, factorB, and response columns, then save the active sheet as a CSV file.




