How to Update Mastersheet

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:

Nested Loops

 

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

One thought on “How to Update Mastersheet”

  1. 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.