Auto fill rows based on data source

jimbomcmucka

New Member
Joined
Oct 11, 2022
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi Guys, hoping you can help?

I am producing a report, extracting and presenting simplified data from a system extract. I am extracting a .csv file from the database and then pasting it into a tab named 'data'. I am then using a tab named 'Report' to show a simplified key data. The data source will differ in length with every extract. I was hoping there may be a way to automate populating the formulas that appear in Row 2 into the correct number of rows to match the data source. e.g. Todays extract contains 821 rows of data. So I would like to automate the equivalent of selecting row 2 and dragging it down to row # 822.

Can anybody advise of the best way to do this?

Many thanks,
Jim
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Put this into a standard code module.

For each column in the Report worksheet it copies down the formula in row 2 if there is one.

VBA Code:
Public Sub subCopyFormulasDown()
Dim WsData As Worksheet
Dim WsReport As Worksheet
Dim rng As Range
Dim lngRows As Long

    Set WsData = Worksheets("Data")
    Set WsReport = Worksheets("Report")
    
    lngRows = WsData.Range("A1").Range("A" & Rows.Count).End(xlUp).Row
    
    For Each rng In WsReport.Range("A1").CurrentRegion.Rows(1).Cells
        If rng.Offset(1, 0).HasFormula = True Then
            rng.Offset(2, 0).Resize(lngRows - 2, 1).Formula = rng.Offset(1, 0).Formula
        End If
    Next rng
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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