KleckerJPK
New Member
- Joined
- Dec 20, 2016
- Messages
- 2
I have created two workbooks: 1) a matrix with prices and 2) details which need to have the prices added. The prices need to be added based on type of loan, group rate, and month. There is a column (BC:BC) added on the 2nd wksheet that has this information in a code that will match codes on the 1st wkbook (col K) next to the appropriate prices indicating which line the price is on (in col E). On the 2nd wkbook there is multiple lines of data and also a cell that shows the count of the data lines (BD2). Here is my macro code that will find and copy the data for one iteration / row:
Sub MBS_Trades()
'
'Define variables
Dim TFile As String
Dim CLVFile As String
Dim CLVPath As String
Dim SFileName As String
Dim CellRange As String
Sheets("Assumptions").Select
TFile = Range("B8")
CLVPath = Range("B10")
CLVFile = Range("B12")
SFileName = Range("B14")
Windows(CLVFile & ".xlsx").Activate
Sheets("MBS Closed Loans Only").Select
Range("BC2").Select
Selection.Copy
Windows(TFile).Activate
Sheets("Assumptions").Select
Range("C31").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Calculate
CellRange = Range("B32")
Sheets("Matrix").Select
Range(CellRange).Select
Selection.Copy
Windows(CLVFile & ".xlsx").Activate
Range("S2").Select ' this is column where the price is to be placed - row 2 is first row
ActiveSheet.Paste
Windows(TFile).Activate
End Sub
I would like to create a loop that will go through each line of data in wkbk 2, read the code in wkbk 2, find the code and corresponding price in wkbk 1, and paste the price in wkbk 2.
Here is the assumptions tab where the variable definitions come from in wkbk 1:
<tbody>
</tbody>
The "14" in row 31 is a vlookup to find which row the code in cell C31 (GNMA I4Mar) is in on the table where the price is located. The "E14" on row 32 is the actual cell address of the price which needs to be copied in wkbk 1. The price needs to be pasted in the same row as the original code was found in wkbk 2.
I have used Excel extensively with complex formulas and also written many macros (VBA) but I am new to creating loops. Any help here would be greatly appreciated. Thanks in advance!
Sub MBS_Trades()
'
'Define variables
Dim TFile As String
Dim CLVFile As String
Dim CLVPath As String
Dim SFileName As String
Dim CellRange As String
Sheets("Assumptions").Select
TFile = Range("B8")
CLVPath = Range("B10")
CLVFile = Range("B12")
SFileName = Range("B14")
Windows(CLVFile & ".xlsx").Activate
Sheets("MBS Closed Loans Only").Select
Range("BC2").Select
Selection.Copy
Windows(TFile).Activate
Sheets("Assumptions").Select
Range("C31").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Calculate
CellRange = Range("B32")
Sheets("Matrix").Select
Range(CellRange).Select
Selection.Copy
Windows(CLVFile & ".xlsx").Activate
Range("S2").Select ' this is column where the price is to be placed - row 2 is first row
ActiveSheet.Paste
Windows(TFile).Activate
End Sub
I would like to create a loop that will go through each line of data in wkbk 2, read the code in wkbk 2, find the code and corresponding price in wkbk 1, and paste the price in wkbk 2.
Here is the assumptions tab where the variable definitions come from in wkbk 1:
col A | B | C | D | E | ||||
row 2 | Current | Year | Month | Day | ||||
3 Today | 03/24/2017 | 2017 | 03 | 24 | ||||
4 | 201703 | = Year Month | ||||||
5 | 20170324 | = Year Month Day | ||||||
6 | ||||||||
7 Filename / Path | H:\MBS Pricing Matrix\[2017-02 MBS EOD Pricing Matrix.xlsm]Assumptions | |||||||
8 This File | 2017-02 MBS EOD Pricing Matrix.xlsm | |||||||
9 | ||||||||
10 File Path | I:\NatRes\Shared\Secondary Reporting\QRM files\QRM Procedures\QRM Reconciliations\ | |||||||
11 | ||||||||
12 File Tamplate | MBS Only for Closed Loans Validation | |||||||
13 | ||||||||
14 Save Template Name | MBS Only for Closed Loans Validation 03-24-2017 | |||||||
15 | ||||||||
16 Report Month | 3 | |||||||
17 | ||||||||
18 Month vlookup | 1 | January | Jan | |||||
19 | 2 | February | Feb | |||||
20 | 3 | March | Mar | |||||
21 | 4 | April | Apr | |||||
22 | 5 | May | May | |||||
23 | 6 | June | Jun | |||||
24 | 7 | July | Jul | |||||
25 | 8 | August | Aug | |||||
26 | 9 | September | Sep | |||||
27 | 10 | October | Oct | |||||
28 | 11 | November | Nov | |||||
29 | 12 | December | Dec | |||||
30 | ||||||||
31 Row Copy Data | 14 | GNMA I4Mar | ||||||
32 Cell Range | E14 |
<tbody>
</tbody>
The "14" in row 31 is a vlookup to find which row the code in cell C31 (GNMA I4Mar) is in on the table where the price is located. The "E14" on row 32 is the actual cell address of the price which needs to be copied in wkbk 1. The price needs to be pasted in the same row as the original code was found in wkbk 2.
I have used Excel extensively with complex formulas and also written many macros (VBA) but I am new to creating loops. Any help here would be greatly appreciated. Thanks in advance!