Is there an easy way to add formulaR1C1 into VBA arrays to speed up calculation time?

ianawwalker

New Member
Joined
Feb 16, 2023
Messages
15
Office Version
  1. 365
  2. 2021
Platform
  1. 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?

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
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi @ianawwalker and thanks for posting on the MrExcel forum.

I understand that this situation is difficult and could be affecting your work, let's work together as a team to find the best solution to this process.

In order for me to better understand the problem, I would like to request a file with data in all sheets and with the expected results. Please, include in your examples 10 to 15 records or the minimum data necessary to understand the operation, on each sheet to know how each formula works.
You could upload a copy of your file to a free site such google drive. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.

I hope to hear from you soon.
Respectfully
Dante Amor
 
Upvote 0
Hi Dante,

I don't have access to be able to send it via google sheets and it won't let me attach it to the chat here. any suggestions on getting that to you?

thankyou,

ian
 
Upvote 0
You can add here a representative sample (15 to 20 records) from each sheet (5 sheets), use the XL2BB tool for that.
NOTE XL2BB:
MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in
Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.

I tried to create the samples of each sheet to see how the sheets work.
I already understood more or less what each formula does, but I need more real or significant data to carry out tests and start creating the macro.

Dante Amor
ABCDEFGHIJKLM
1ABCDEFGHIJKLM
2A2B2C2D2E2F2G2H2I2J2K2L2M2
3A2B3C3D3E3F3G3H3I3J3K3L3M3
4A2B4C4D4E4F4G4H4I4J4K4L4M4
5A2B5C5D5E5F5G5H5I5J5K5L5M5
6A6B6C6D6E6F6G6H6I6J6K6L6M6
7A6B7C7D7E7F7G7H7I7J7K7L7M7
8A6B8C8D8E8F8G8H8I8J8K8L8M8
9A9B9C9D9E9F9G9H9I9J9K9L9M9
US_FileInput


Dante Amor
ABCDEFGHIJKLMNOPQRSTU
1ABCDEFGHIJKLMNOPQRSTU
2A2S2U2C2D2E2F2G2H2I2J2K2L2M2N2O2P2Q2R2S2T2U2
3A2S3U3C3D3E3F3G3H3I3J3K3L3M3N3O3P3Q3R3S3T3U3
4A2S4U4C4D4E4F4G4H4I4J4K4L4M4N4O4P4Q4R4S4T4U4
5A2S5U5C5D5E5F5G5H5I5J5K5L5M5N5O5P5Q5R5S5T5U5
6A6S6U6C6D6E6F6G6H6I6J6K6L6M6N6O6P6Q6R6S6T6U6
7A6S7U7C7D7E7F7G7H7I7J7K7L7M7N7O7P7Q7R7S7T7U7
8A6S8U8C8D8E8F8G8H8I8J8K8L8M8N8O8P8Q8R8S8T8U8
9A9S9U9C9D9E9F9G9H9I9J9K9L9M9N9O9P9Q9R9S9T9U9
US_Exceptions
Cell Formulas
RangeFormula
B2:B9B2=S2&U2


Cell Formulas
RangeFormula
C2:F9C2=SUM(COUNTIFS(US_Exceptions!$A:$A,US_Combine!$A2,US_Exceptions!$B:$B,INDEX(US_Codes!B$2:B$11,0)))
I2:I9I2=VLOOKUP(A2,Records!A:AN,34,FALSE)
J2:J9J2=VLOOKUP(A2,Records!A:AN,29,FALSE)
K2:K9K2=VLOOKUP(A2,Records!A:AN,39,FALSE)
L2:L9L2=VLOOKUP(A2,Records!A:AO,39,FALSE)
M2:P9M2=MATCH(Q2,I2,0)
Q2:T9Q2=IF(C2>=1,"Y","N")
U2:U9U2=MATCH(A2,Records!A:A,0)


Dante Amor
ABC
1
2S2U2
3S2U3
4S2U4
5S2U5
6
US_Codes


Dante Amor
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAI
11234567891011121314151617181920212223242526272829303132333435
2a2esto q
3A3es3
4A4es4
5A5es5
6A6es6
7A7es7
8A8es8
9A9es9
Records


Your examples are important, otherwise I would be guessing how your data is and I would not reach a definitive result and I would be modifying the macro many times and you would be testing a macro many times that would not reach the final goal.

----- --
I hope to hear from you soon.
Respectfully
Dante Amor
 
Upvote 0
Hi Dante,

I hope this helps, but i'm not able to download the XL2BB onto my computer unfortunately. Here are some screenshots of my file with fake info that resembles my confidential information I have.
 

Attachments

  • Offline.PNG
    Offline.PNG
    39.4 KB · Views: 29
  • Records.PNG
    Records.PNG
    66.6 KB · Views: 23
  • US Codes.PNG
    US Codes.PNG
    14 KB · Views: 23
  • US_Combine - Empty.PNG
    US_Combine - Empty.PNG
    22.1 KB · Views: 21
  • US_Exceptions.PNG
    US_Exceptions.PNG
    31.7 KB · Views: 20
  • US_FileInput.PNG
    US_FileInput.PNG
    58.3 KB · Views: 19
  • C-F Formula.PNG
    C-F Formula.PNG
    21.2 KB · Views: 25
  • I-L Formula.PNG
    I-L Formula.PNG
    17.7 KB · Views: 21
  • M-P Formula.PNG
    M-P Formula.PNG
    18.1 KB · Views: 17
  • Q-T Formula.PNG
    Q-T Formula.PNG
    17.1 KB · Views: 9
  • U Formula.PNG
    U Formula.PNG
    19.4 KB · Views: 21
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,148
Members
452,615
Latest member
bogeys2birdies

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