helpneeded2
Board Regular
- Joined
- Jun 25, 2021
- Messages
- 110
- Office Version
- 365
- Platform
- Windows
I am trying to create a spreadsheet that will be used by multiple people in which data from a an SQL pull will be pasted into the sheet. This data may vary from 100 rows of data to 20,000 rows.
For best sheet performance I would like to avoid having a formula in 20,000 rows that tests whether there is data in each of the rows, and outputs a value if there is data. My sheet has several similar data tabs, and when I placed in the formula down the 20,000 rows on each tab, the sheet size increased 10-fold and the time to calculate is now measured in minutes.
Although I have had very minimal exposure to VBA, I would like to have a script that would copy a formula from the first row (adjacent to existing data), and paste it down the column for every other adjacent row with data.
To help simplify what I am trying to do, here is an example:
In the above example, I want any formula in C1 to be copied down to the last row in Column C in which data exists in Column A.
While looking at examples from a browser search, I think the most accurate VBA I found was this:
However when I try to run this I get an error. (Run-time error '1004': AutoFill method of Range class failed)
Could someone please post a suggestion on how I could do this.
Thank you.
For best sheet performance I would like to avoid having a formula in 20,000 rows that tests whether there is data in each of the rows, and outputs a value if there is data. My sheet has several similar data tabs, and when I placed in the formula down the 20,000 rows on each tab, the sheet size increased 10-fold and the time to calculate is now measured in minutes.
Although I have had very minimal exposure to VBA, I would like to have a script that would copy a formula from the first row (adjacent to existing data), and paste it down the column for every other adjacent row with data.
To help simplify what I am trying to do, here is an example:
A | B | C | D | |
1 | 22 | 23 | =A1+B1 | |
2 | 44 | 23 | ||
3 | 2343 | 339 | ||
4 |
In the above example, I want any formula in C1 to be copied down to the last row in Column C in which data exists in Column A.
While looking at examples from a browser search, I think the most accurate VBA I found was this:
VBA Code:
Sub test()
Dim lastrow As Long
lastrow = Range("A" & Rows.Count).End(xlUp).Row
Range("C1").AutoFill Destination:=Range("C2:C" & lastrow), Type:=xlFillDefault
End Sub
However when I try to run this I get an error. (Run-time error '1004': AutoFill method of Range class failed)
Could someone please post a suggestion on how I could do this.
Thank you.