Auto copy formula from a cell, to other cells when adjacent cell on row contains data?

helpneeded2

Board Regular
Joined
Jun 25, 2021
Messages
110
Office Version
  1. 365
Platform
  1. 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:

ABCD
12223=A1+B1
24423
32343339
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.
 
As your question is signifcantly different from the op, you need to start a new thread. Thanks
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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