ianawwalker
New Member
- Joined
- Feb 16, 2023
- Messages
- 15
- Office Version
- 365
- 2021
- Platform
- Windows
Hello,
I am putting in a bunch of formulas into 10 columns, that goes down 12,000 times or more. Which is causing the VBA to slow down exponentially. I do not have much experience with arrays and was thinking there should be a way to add my worksheets into different arrays, put the calculations into one of the arrays and then paste the data into my final worksheet that i am using to update a different worksheet. For instance I have data that I am combining from US_FileInput and US_Exceptions that goes into US_Combine. The US Combine takes a bunch of time to run the calculations, because of the formulas i am using to translate the data from a vendor to my companies reporting. The VBA works to translate this data, but takes anywhere from 15-30 min to run. Is there a way to put all of the worksheets into arrays, run the calculations in arrays, and then have the data spit back out into my final worksheet of US_Combine?
I am putting in a bunch of formulas into 10 columns, that goes down 12,000 times or more. Which is causing the VBA to slow down exponentially. I do not have much experience with arrays and was thinking there should be a way to add my worksheets into different arrays, put the calculations into one of the arrays and then paste the data into my final worksheet that i am using to update a different worksheet. For instance I have data that I am combining from US_FileInput and US_Exceptions that goes into US_Combine. The US Combine takes a bunch of time to run the calculations, because of the formulas i am using to translate the data from a vendor to my companies reporting. The VBA works to translate this data, but takes anywhere from 15-30 min to run. Is there a way to put all of the worksheets into arrays, run the calculations in arrays, and then have the data spit back out into my final worksheet of US_Combine?
VBA Code:
Sub UScombine_moveUSdatatoUScombine()
'Application.ScreenUpdating = False
'Call TurnoffFunctionality
Sheets("US_FileInput").Range("A:A").TextToColumns
Sheets("US_Exceptions").Range("A:A").TextToColumns
'copy loan numbers & info to db_combine tab
'loan number & 'alt loan & borrower & address
Worksheets("US_FileInput").Range("A2:A25000").Copy
Worksheets("US_Combine").Range("A2").PasteSpecial xlPasteValues
Worksheets("US_FileInput").Range("H2:H25000").Copy
Worksheets("US_Combine").Range("B2").PasteSpecial xlPasteValues
Worksheets("US_FileInput").Range("I2:I25000").Copy
Worksheets("US_Combine").Range("G2").PasteSpecial xlPasteValues
Worksheets("US_FileInput").Range("M2:M25000").Copy
Worksheets("US_Combine").Range("H2").PasteSpecial xlPasteValues
'Application.ScreenUpdating = True
'create exception code for Y/N conversion
With Sheets("US_Exceptions")
.Range("B2:B25000").ClearContents
.Range("B2:B" & .Cells(Rows.Count, 1).End(xlUp).Row).FormulaR1C1 = "=RC[17]&RC[19]"
'worksheets("US_Exceptions").Range("B2:B" & Cells(Rows.Count, 3).End(xlUp).Row).Value = Range("B2:B" & Cells(Rows.Count, 3).End(xlUp).Row).Value
End With
'calculation from Tim on Y/N conversion, input info here and paste into DB_Combine
With Sheets("US_Combine")
.Range("C2:C" & .Cells(Rows.Count, 1).End(xlUp).Row).Formula2R1C1 = _
"=SUM(COUNTIFS(US_Exceptions!C1,US_Combine!RC1,US_Exceptions!C2,INDEX(US_Codes!R2C[-1]:R11C[-1],0)))"
.Range("D2:D" & .Cells(Rows.Count, 1).End(xlUp).Row).Formula2R1C1 = _
"=SUM(COUNTIFS(US_Exceptions!C1,US_Combine!RC1,US_Exceptions!C2,INDEX(US_Codes!R2C[-1]:R11C[-1],0)))"
.Range("E2:E" & .Cells(Rows.Count, 1).End(xlUp).Row).Formula2R1C1 = _
"=SUM(COUNTIFS(US_Exceptions!C1,US_Combine!RC1,US_Exceptions!C2,INDEX(US_Codes!R2C[-1]:R11C[-1],0)))"
.Range("F2:F" & .Cells(Rows.Count, 1).End(xlUp).Row).Formula2R1C1 = _
"=SUM(COUNTIFS(US_Exceptions!C1,US_Combine!RC1,US_Exceptions!C2,INDEX(US_Codes!R2C[-1]:R11C[-1],0)))"
'.Range("C2:F" & Cells(Rows.Count, 1).End(xlUp).Row).Value = Range("C2:F" & Cells(Rows.Count, 1).End(xlUp).Row).Value
End With
'comparing records tab to exception report & match formula to records tab & converting 1/0's to Y/N's to copy/paste to records tab
With Sheets("US_Combine")
.Range("I2:I" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-8],Records!C[-8]:C[31],34,FALSE)"
.Range("J2:J" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-9],Records!C[-9]:C[30],29,FALSE)"
.Range("K2:K" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-10],Records!C[-10]:C[29],39,FALSE)"
.Range("L2:L" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=VLOOKUP(RC[-11],Records!C[-11]:C[29],39,FALSE)"
.Range("M2:M" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=MATCH(RC[4],RC[-4],0)"
.Range("N2:N" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=MATCH(RC[4],RC[-4],0)"
.Range("O2:O" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=MATCH(RC[4],RC[-4],0)"
.Range("P2:P" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=MATCH(RC[4],RC[-4],0)"
.Range("U2:U" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=MATCH(RC[-20],Records!C[-20],0)"
.Range("Q2:Q" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=IF(RC[-14]>=1,""Y"",""N"")"
.Range("R2:R" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=IF(RC[-14]>=1,""Y"",""N"")"
.Range("S2:S" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=IF(RC[-14]>=1,""Y"",""N"")"
.Range("T2:T" & Cells(Rows.Count, 3).End(xlUp).Row).FormulaR1C1 = "=IF(RC[-14]>=1,""Y"",""N"")"
'.Range("I2:U" & .Cells(Rows.Count, 1).End(xlUp).Row).Value = Range("I2:U" & .Cells(Rows.Count, 1).End(xlUp).Row).Value
End With
End Sub