Use Excel VBA to Copy Source Cells to the Same Master Sheet Row
Question details
The user needs a VBA macro to copy values from each source worksheet into a single corresponding row on a Master sheet.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A macro consolidates cells from multiple worksheets into a Master sheet, with one row per source worksheet.
- Observed behavior
- When source cells are blank, copied values can be placed on different destination rows.
Confirm that the workbook has a sheet named Master and identify the source cells and destination columns you want to use. Save the workbook in a macro-enabled format such as .xlsm, and run macros only from trusted sources.
Calculate one destination row per source worksheet
Use the same destination row for every value copied from a worksheet, so blank source cells do not shift other fields.
This example copies B2, B3, and B4 from each worksheet into columns A, B, and C of Master. Change the cell references and destination columns to match your workbook. The macro skips Master but processes every other worksheet.
The next row is based on the last used cell anywhere on Master, including cells containing formulas. If Master is empty, the first source worksheet is written to row 1.
In Excel, open Developer > Visual Basic, then select the workbook containing the Master and source sheets.
Choose Insert > Module and paste this code: Sub CopyToMaster() Dim ws As Worksheet Dim master As Worksheet Dim lastUsed As Range Dim nextRow As Long Set master = ThisWorkbook.Worksheets("Master") For Each ws In ThisWorkbook.Worksheets If ws.Name <> master.Name Then Set lastUsed = master.Cells.Find(What:="*", _ After:=master.Cells(1, 1), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlPrevious, MatchCase:=False) If lastUsed Is Nothing Then nextRow = 1 Else nextRow = lastUsed.Row + 1 End If master.Cells(nextRow, 1).Value = ws.Range("B2").Value master.Cells(nextRow, 2).Value = ws.Range("B3").Value master.Cells(nextRow, 3).Value = ws.Range("B4").Value End If Next ws End Sub
Edit the B2, B3, and B4 references and the destination column numbers as needed. In Excel, choose Developer > Macros, select CopyToMaster, and click Run.
Open Master and verify that each source worksheet's values appear together in one row, with blank source values left blank.

Work with Master Sheets in WPS Office
WPS Office is a free, lightweight alternative for working with spreadsheets in a familiar interface. Its Excel format compatibility makes it easy to move existing workbooks between applications. Check macro support in your WPS edition before relying on an Excel VBA workflow.

Frequently Asked Questions
Why do blank source cells cause values to end up on different rows?
If the macro recalculates the next empty row separately for each field, a blank value can affect where the following value is written. Calculate nextRow once per source worksheet and use it for every destination cell.
How can I write zero instead of leaving a source cell blank?
Replace the relevant assignment with an If statement, for example: If IsEmpty(ws.Range("B2").Value) Then master.Cells(nextRow, 1).Value = 0 Else master.Cells(nextRow, 1).Value = ws.Range("B2").Value. A formula that returns an empty string is not an empty cell, so it needs a separate check.
Will the macro overwrite my Master sheet headers?
If the headers are already present, the macro writes below the last used row. If Master is completely empty, it starts at row 1, so add headers before running it if you need them.
What happens if I run the macro more than once?
The macro appends another set of rows below the existing data; it does not detect duplicates. Review or clear the previous output on Master before running it again if duplicates are unwanted.
Does the macro copy formatting or formulas?
No. The .Value assignments copy the current values only. They do not copy source formatting or the formulas that produced those values.




