Insert and delete rows and columns in a worksheet
Inserting and deleting rows and columns changes the shape of the worksheet: a row for a reading that was left out, no rows for setup parts that should never have been logged, a new column for the operator, no column for notes you no longer need. In a statistics worksheet each row is usually one part, one sample or one run, so these commands always act on whole rows across every column. That keeps each part's values together.
When to use it
- Setup pieces, test shots or first-off parts were logged with production parts and must not count in a capability study.
- A reading is missing from the log and you find it on the paper record: it needs a row in the right place, so the time order stays correct for a run chart or a control chart.
- You want a new column between existing ones, for example an operator or a lot column next to the part number.
- A column holds notes or intermediate results you no longer need.
To delete rows that meet a condition, such as every row from the night shift, Subset worksheet is faster than selecting them by hand.
How to do it in StatLab
These four commands are in the Data menu. They act on the cells you have selected and open no dialog.
- Select first. Click a row number to select a whole row, or a column label (C1, C2…) to select a whole column. Shift+click another row number or label to extend the selection. Selecting ordinary cells works too: the commands use the rows or columns your selection covers.
- Choose the command:
- Data › Insert rows adds as many empty rows as you have selected, above the selection. Every column moves down from there, so rows stay together.
- Data › Delete rows deletes the selected rows from every column.
- Data › Insert columns adds as many empty columns as you have selected, to the left of the selection.
- Data › Delete columns deletes the selected columns with their names. Columns to the right move left and take new labels (C4 becomes C3).
- Results records what changed, such as Deleted rows 1 to 2. Each command is one step that Ctrl+Z undoes.
An inserted row is empty: it shows * (missing) in numeric and date columns and a blank in text columns until you type values.
Example
An inspector measures the gap between a door panel and its frame (mm) on a gage block and logs the readings by sample number. The log has three problems: samples 1 and 2 were setup pieces, sample 5 was written on paper but never typed, and the Note column is only there for the setup pieces.
Before:
| C1 Sample | C2-T Note | C3 Gap (mm) |
|---|---|---|
| 1 | setup | 0.52 |
| 2 | setup | 0.47 |
| 3 | 0.42 | |
| 4 | 0.44 | |
| 6 | 0.41 | |
| 7 | 0.45 |
- Delete the setup rows. Click row number 1, Shift+click row number 2, and choose Data › Delete rows. Results: Deleted rows 1 to 2. Samples 3 to 7 move up to rows 1 to 4.
- Insert the missing reading. Click any cell in row 3 (sample 6) and choose Data › Insert rows. Results: Inserted an empty row before row 3. Row 3 now shows * for Sample and Gap. Type
5and0.43. - Delete the Note column. It is now empty. Click the C2 label and choose Data › Delete columns. Results: Deleted column C2. Gap moves from C3 to C2.
- Make room for the operator. Click the C2 label and choose Data › Insert columns. Results: Inserted an empty column before C2. Gap moves back to C3, and C2 is ready for the operator's initials.
After:
| C1 Sample | C2 | C3 Gap (mm) |
|---|---|---|
| 3 | 0.42 | |
| 4 | 0.44 | |
| 5 | 0.43 | |
| 6 | 0.41 | |
| 7 | 0.45 |
Every reading is still next to its sample number, and the samples are in time order again.
How to read the results
- Read the Output pane after each command. It names the rows or columns that changed, so you can confirm you deleted rows 1 to 2 and not 1 to 20.
- Check the column labels. After deleting or inserting columns, labels shift. A formula or a note that says "C3" may now mean a different column; refer to columns by name where you can.
- Look for * in inserted rows. An empty inserted row counts as a missing value in every numeric column until you fill it. If you insert a row by mistake, delete it or undo, or it adds to N* in later analyses.
Common mistakes
- Clearing cells instead of deleting rows. Delete on the keyboard empties cells but keeps the rows, so the values below do not move up and other columns keep their values in that row. To remove a part from the data, delete its row.
- Deleting rows in one column only. Cutting values out of one column and pasting them higher up shifts that column against the others, so measurements end up next to the wrong part numbers. Data › Delete rows always removes the whole row.
- Selecting the wrong rows. Long selections are easy to overshoot. Check the row numbers in the Output pane, and undo at once if they are wrong.
- Deleting data you will need for the record. Removing setup parts from an analysis is fine; losing the record of them is not. Save a project file first, or keep the full data in another project.
Frequently asked questions
How do I delete many rows that meet a condition?
Use Data › Subset worksheet… with a condition such as Note = "setup" and choose Delete these rows. It tells you how many rows remain before it changes anything.
Can I undo a deletion?
Yes. Each command is one step in the undo history, up to 100 steps back. Press Ctrl+Z.
Do column names move with the columns?
Yes. Deleting a column removes its name with it, and the names of the columns to the right move left with their data.
Why did a column label lose its -T ending?
A label shows -T or -D only while the column holds data. In the example, the Note column became empty after the setup rows were deleted, so its label changed from C2-T to C2.