Consulting

Results 1 to 3 of 3

Thread: Copy a formula on a worksheet by the number of data rows on a different sheet

  1. #1

    Copy a formula on a worksheet by the number of data rows on a different sheet

    I have a spread sheet that concatenates information from a different sheet that is downloaded. The down loaded information varies in the number of rows at each download. I need to have the script count the active rows and then move to the next spreadsheet and copy the concatenation formula down the same number of rows. ie data range A1:C302 (Row 1 being header) on downloaded sheet. Move to formula sheet and copy A2:C2 down to row 302, remembering the rows are variable from download to download and that next time there may be 305 rows or 275 rows.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Here is an example.


    Option Explicit
     
    Sub AddFormulas()
    Dim LastRow         As Long
    LastRow = Sheets("Sheet1").Range("A65536").End(xlUp).Row
        Sheets("Sheet2").Range("B2").Copy Destination:=Sheets("Sheet1").Range("B2:B" & LastRow)
    End Sub

    Since you are working with multiple workbooks you will need to specify the workbook name before the sheet name.

    Workbooks("Workbook1Name").Sheets("Sheet1").Range ...
    Last edited by Aussiebear; 04-27-2023 at 08:09 PM. Reason: Adjusted the code tags

  3. #3
    Worked Great

    Thanks......

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •