How to Update Excel Records from a Separate Price List using VBA
Question details
The user needs to update prices in an Excel database sheet based on item numbers found in a separate price list sheet.

- Product
- Excel
- Device & OS
- not provided
- Scenario
- Managing large datasets where a master database requires bulk price updates from a secondary sheet, potentially involving duplicate update entries.
- Observed behavior
- The user wants to match item numbers across two sheets and replace the corresponding prices automatically using VBA.
Before running any VBA macros, always save a backup copy of your Excel workbook, as actions performed by macros generally cannot be undone with the standard Undo function.
Use a VBA Macro to Match and Update Prices
Run a customized VBA script to automatically cross-reference item numbers between two sheets and update the prices in bulk.
Using a Visual Basic for Applications (VBA) macro is the most efficient way to cross-reference data between two sheets. This approach eliminates manual copying and pasting, making it ideal for large datasets.
The logic of the macro assumes your database is on Sheet1 and your update sheet is on Sheet2. It loops through the item numbers in column A of Sheet2, finds the match in column A of Sheet1, and overwrites the price in column B.
In your Excel workbook, press ALT + F11 to open the VBA Editor. Alternatively, navigate to the Developer tab on the ribbon and click 'Visual Basic'.
In the VBA Editor, click 'Insert' from the top menu and select 'Module' to create a blank script window where you can write your code.
Paste your macro code into the module. Ensure the code logic identifies Sheet2 as the source, searches for the corresponding item number in Sheet1, and assigns the new price value to the correct cell.
Click anywhere inside your pasted code and press F5, or click the green 'Run' button in the top toolbar to execute the script and update your database.

Easily Manage VBA Macros and Large Datasets with WPS Spreadsheet
WPS Spreadsheet provides robust, built-in support for VBA macros, allowing you to automate data updates, cross-reference sheets, and manage complex databases efficiently without switching software.
- 1. Open Your Workbook: Launch WPS Spreadsheet and open your macro-enabled workbook or standard dataset.
- 2. Enable the Developer Tab: Navigate to the Tools tab and click 'Developer' to access the macro environment.
- 3. Run Your Macros: Click 'Visual Basic Editor', paste your update script, and execute it to automatically match and replace prices.

Frequently Asked Questions
How do I display the Developer tab in Excel to use VBA?
Go to File > Options > Customize Ribbon. In the right pane under Main Tabs, check the box next to 'Developer', then click OK. The tab will now appear on your ribbon.
Can I undo changes made by a VBA macro?
No, actions executed by a VBA macro typically clear the undo stack and cannot be reversed using Ctrl+Z. Always create a copy of your file before running a new script.
What if my item numbers and prices are in different columns?
You need to adjust the column references in your VBA code. For example, if your item numbers are in column C instead of A, change the range definitions in your macro from 'A' to 'C' before running it.




