ianawwalker
New Member
- Joined
- Feb 16, 2023
- Messages
- 15
- Office Version
- 365
- 2021
- Platform
- Windows
I need to combine two files to find data points, which i have the VBA for, but am struggling to write the vba to update a cell if it doesn't match the data in my combined file. found if statements, but they run extremely slow and these files have a large amount of data within them. see my current vba below. thank you for any help!
VBA Code:
Sub DB_Combine_InportToRecords()
Application.ScreenUpdating = False
Call TurnoffFunctionality
Sheets("DB_FileInput").Range("N:N").TextToColumns
Sheets("DB_Exceptions").Range("B:B").TextToColumns
'copy loan numbers & info to db_combine tab
'loan number
Worksheets("DB_FileInput").Range("n3:n25000").Copy
Worksheets("DB_Combine").Range("A2").PasteSpecial xlPasteValues
'alt loan #
Worksheets("DB_FileInput").Range("o3:o25000").Copy
Worksheets("DB_Combine").Range("b2").PasteSpecial xlPasteValues
'borrower
Worksheets("DB_FileInput").Range("p3:p25000").Copy
Worksheets("DB_Combine").Range("f2").PasteSpecial xlPasteValues
'address
Worksheets("DB_FileInput").Range("t3:t25000").Copy
Worksheets("DB_Combine").Range("g2").PasteSpecial xlPasteValues
'pulling in data from records tab matching loan numbers
With Sheets("DB_Combine")
.Range("H2:H" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-7],Records!C[-7]:C[31],39,FALSE)"
.Range("I2:I" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-8],Records!C[-8]:C[30],34,FALSE)"
.Range("J2:J" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-9],Records!C[-9]:C[29],24,FALSE)"
End With
'comparing records tab to exception report
With Sheets("DB_Combine")
.Range("K2:K" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=MATCH(RC[-8],RC[-3],0)"
.Range("L2:L" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=MATCH(RC[-9],RC[-4],0)"
.Range("M2:M" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=MATCH(RC[-10],RC[-5],0)"
End With
'if statement to find any changes that need to be done in records tab (Y)
With Sheets("DB_Combine")
.Range("N2:N" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=IF(AND(RC[-6]=""Y"",RC[-3]=0),""Y"",""N"")"
.Range("O2:O" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=IF(AND(RC[-6]=""Y"",RC[-3]=0),""Y"",""N"")"
.Range("P2:P" & Cells(Rows.Count, 2).End(xlUp).Row).FormulaR1C1 = "=IF(AND(RC[-6]=""Y"",RC[-3]=0),""Y"",""N"")"
End With
'pasting value instead of formulas
Dim LastRowColumnA As Long
LastRowColumnA = Cells(Rows.Count, 1).End(xlUp).Row
Sheets("DB_Combine").Range("H2:P" & LastRowColumnA).Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'match DB exception Y/N to Records index/match and paste (1,0) in to columns K, L, & M
'if any loan from column A has a 0 in column K, need it to update cell (in column AM) in "Records" sheet to put a "Y". only want cell to update if column K has a 0, if column K has a 1 do not change value
MsgBox ("DB File Uploaded")
'clear contents
Range("DB_Input").ClearContents
Sheets("DB_Input").Select
Application.ScreenUpdating = True
Call TurnOnFunctionality
End Sub
Last edited by a moderator: