Excel - updating records by comparision - VBScript/Macros

sowmyareddy

New Member
Joined
Apr 1, 2019
Messages
8
  • Hi,

    Can someone please provide me a VBScript code for my below requirement.

    I have a master tracking document that I use to record project information. My client sends me an updated schedule each week which may (or may not) have additional stores on it and some of the details of the stores may have changed. I need a macro to capture these changes from the source spreadsheet (the one the client sends) and update the master tracker. The master tracker has a lot of additional columns of data that I add in myself about each project so I don't want to lose this information. The macro needs to see if the store on the source sheet is already on the master tracker and if it is then it needs to check to see. If the store isn't on the master tracker then it needs to be added. Also, delete any rows from the master tracker if they have now been removed from the source workbook.

    Master Spreadsheet

    Column A - Member
    Column B - Description
    Column C - Structure-1
    Column D - Structure-2
    Column E - Structure-3
    Column F - Currency
    Column G - Geography
    Column H - Business


    Source Spreadsheet

    Column K - Member
    Column L - Description
    Column M - Structure-1
    Column N - Structure-2
    Column O - Structure-3
    Column P - Currency
    Column Q - Geography
    Column R - Business


    Quick response would be appreciated!

    Thanks in Advance.

    Regards,
    Sowmya​
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
so, if for example member3 is on the master but not on the source, delete that row on the master ? And if there is a member2 on each sheet, do you want to over-write the master with the "newest" information ?
 
Upvote 0
Delete member3 from master data sheet
If there is a new member found in the source sheet, update it in master sheet(also, any updated column found for a member existing in source sheet, the same has to be updated in master sheet).


Can you please provide the vbscript code or a macro asap.

Thanks in advance.


Regards,
Sowmya.
 
Upvote 0
member199
member288
member377source
member466
member555member199
member377
member4888
member555
member6333
new master
member199
member3777
member4888
member555
member6333
is this the desired outcome

<colgroup><col width="64" span="14" style="width:48pt"> </colgroup><tbody>
</tbody>
 
Upvote 0
member199no changecol L
member288delete
member377no changesource
member466change to 888
member555no changemember199row 5
mytable > > > > >member377
member4888
member555
member6333add
formulas in column C and L5:L9 tell you what actions are needed
in the short term you can use this to highlight necessary changes
C1
=IF(ISERROR(OFFSET($J$4,MATCH(A1,$J$5:$J$9,0),0)),"delete",IF(VLOOKUP(A1,mytable,2)=B1,"no change","change to "&VLOOKUP(A1,mytable,2)))
L5
=IF(COUNTIF($A$1:$A$5,J5)>0,"","add")

<colgroup><col span="2"><col><col span="15"></colgroup><tbody>
</tbody>
 
Upvote 0
I have given you formulas that tell you where to make changes. A totally automatic macro will take - me at least - several hours to develop. If you do not understand how my two formulas work, then if you had a macro and it did not work properly under certain circumstances, how would you fix it ?
 
Upvote 0
Hi Oldbrewer,

I am new to vbscripting/macros. I have tried a code (below) mentioned in one of the posts which is similar to my request. But, I am ending up with a data adding in a single row in master sheet instead of adding all the newly added data in source workbook to master workbook. Please let me know if I can do something in the below code so that if there is a change in source sheet, the same has to be updated in master sheet.

Sub Test()
Dim wbSource As Workbook
Dim wsSource As Worksheet
Dim Rng As Range
Dim wbMaster As Workbook
Dim wsMaster As Worksheet
Dim Cell As Range
Dim Target As Range
Dim r As Long
Set wbSource = Workbooks("Source.xls")
Set wsSource = wbSource.Worksheets("Sheet1")
With wsSource
Set Rng = .Range("D2:D" & .Range("D" & .Rows.Count).End(xlUp).Row)
End With
Set wbMaster = Workbooks("Master.xls")
Set wsMaster = wbMaster.Worksheets("Sheet1")
With wsMaster
For Each Cell In Rng
With .Columns("B")
Set Target = Nothing
Set Target = .Find(What:=Cell.Value, After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
End With
If Not Target Is Nothing Then
r = Target.Row
Else
r = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
End If
.Range("A" & r).Value = Cell.EntireRow.Range("C" & 1).Value
.Range("B" & r).Value = Cell.EntireRow.Range("D" & 1).Value
.Range("C" & r).Value = Cell.EntireRow.Range("I" & 1).Value
.Range("D" & r).Value = Cell.EntireRow.Range("J" & 1).Value
.Range("E" & r).Value = Cell.EntireRow.Range("M" & 1).Value
.Range("F" & r).Value = Cell.EntireRow.Range("N" & 1).Value
.Range("I" & r).Value = Cell.EntireRow.Range("P" & 1).Value
.Range("J" & r).Value = Cell.EntireRow.Range("Q" & 1).Value
Next Cell
For r = .Range("B" & .Rows.Count).End(xlUp).Row To 2 Step -1
If WorksheetFunction.CountIf(Rng, .Range("b" & r).Value) = 0 Then
.Rows(r).Delete
End If
Next r
End With
End Sub


Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,692
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top