How to update mastersheet using updated data in monthly reports. Often we update our manpower data if we are a recruitment firm or our purchase prices if we are a sales or production organization. In such cases we may need to update our master data. We learn today how this process of updating of data can be automated using Excel VBA. Watch the video below:
Watch this video on YouTube.
Here’s the complete VBA code for updating data in a master worksheet with VBA:
Sub updateMasterSheetFromMonthlyReport()
Dim personName As String, companyName As String
Application.ScreenUpdating = False
Workbooks.Open (“C:\Users\takyar\Desktop\mymonthlyreport.xlsx”)
Worksheets(“sheet1”).Select
lastrowMR = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To lastrowMR
personName = Cells(i, 1)
companyName = Cells(i, 2)
Windows(“mymastersheet.xlsm”).Activate
Sheet1.Activate
lastrowMS = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
For p = 2 To lastrowMS
If Cells(p, 1) = personName And Cells(p, 2) <> companyName Then
Cells(p, 1) = personName
Cells(p, 2) = companyName
End If
Next p
Windows(“mymonthlyreport.xlsx”).Activate
Next i
Windows(“mymonthlyreport.xlsx”).Close
Application.ScreenUpdating = True
End Sub
Further reading:
Hello Dinesh,
Thank you for this code, I am currently using a variation of it to update 13000 part number prices. This has been working very well. Although now if possible I would like to update/compare the prices from different columns based on a cell value which matches the headers on my master sheet.
So when I select a customer group it updates the column with the matching header for that group.
“aCell” matches the header but I can’t workout how to make the column number dynamic in the Cells(p, 8) fields.
If you have a solution that would be appreciated!!
#Code
Dim partNumber As String, specialPrice As String
Application.ScreenUpdating = False
Worksheets(“QUOTE TEMPLATE”).Activate
lastrowMR = Sheets(“QUOTE TEMPLATE”).Cells(Rows.Count, 1).End(xlUp).Row
For I = 18 To lastrowMR
partNumber = Cells(I, 2).Value
specialPrice = Cells(I, 6).Value
Worksheets(“PRICING DATABASE”).Activate
myHdr = Sheets(“Quote Template”).Range(“O1”)
Set aCell = Sheets(“PRICING DATABASE”).Range(“A1:Z1”).Find(What:=myHdr, _
LookIn:=xlValues, LookAt:=xlWhole, _
MatchCase:=False, SearchFormat:=False)
lastrowMS = Sheets(“PRICING DATABASE”).Cells(Rows.Count, 1).End(xlUp).Row
For p = 2 To lastrowMS
If Cells(p, 3) = partNumber And Cells(p, 8) specialPrice Then
Cells(p, 3) = partNumber
Cells(p, 8) = specialPrice
End If
Next p
Worksheets(“QUOTE TEMPLATE”).Activate
Next I
Application.ScreenUpdating = True