Sub MyDataUpdater()
Dim mcrWB As Workbook
Dim datWB As Workbook
Dim strFile As Variant
Dim lr As Long, r As Long
Dim oldVal As String, newVal As String
Dim lr2 As Long
Dim rng As Range
' Capture macro workbook
Set mcrWB = ThisWorkbook
' Sort price change data in ascending order
Range("A1").CurrentRegion.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom
' Find last row in column A
lr = Cells(Rows.Count, "A").End(xlUp).Row
' Browse to open CSV file
strFile = Application.GetOpenFilename(FileFilter:="CSV Files (*.csv),*.csv", Title:="Choose a CSV file to open", MultiSelect:=False)
' Check selection and proceed accordingly
If strFile <> False Then
' Open and capture workbook
Set datWB = Application.Workbooks.Open(strFile)
Else
' Exit if operation cancelled
MsgBox "Operation cancelled", vbOKOnly
Exit Sub
End If
Application.ScreenUpdating = False
' Reformat column D to show all 12 digits on data file
Columns("D:D").NumberFormat = "000000000000"
' Find last row in column G with data
lr2 = Cells(Rows.Count, "G").End(xlUp).Row
' Set range to replace
Set rng = Range("G1:G" & lr2)
' Loop through all prices changes in macro file listing
For r = lr To 2 Step -1
' Get old and new price values
mcrWB.Activate
oldVal = Round(Cells(r, "A").Value, 2)
newVal = Round(Cells(r, "B").Value, 2)
' Replace values in column G on data file
datWB.Activate
rng.Replace What:=oldVal, Replacement:=newVal, LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
Next r
' Re-Save file and close
datWB.Save
datWB.Close
MsgBox "Macro complete!"
Application.ScreenUpdating = True
End Sub