ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Macro to copy range of formulas to equal data lines (https://www.excelbanter.com/excel-worksheet-functions/39040-macro-copy-range-formulas-equal-data-lines.html)

lh

Macro to copy range of formulas to equal data lines
 
I would like to have a macro to copy a range of formulas in row 2 down for
all lines of input in an adjacent range. For example:

Input Formula
Row 2 Cell X2 Cell Y2
Row 3
Row 4
Row 5

In input date in the range Row2 through Row 5. I want to copy the formulas
in Cells X2 and Y2 down for the other three lines of input.

Thanks for any help that you can provide.

Dave Peterson

Hmmm. What column gets the dates?

Option Explicit
Sub testme01()

Dim LastRow As Long
Dim FirstRow As Long

With ActiveSheet
FirstRow = 2 'headers in row 1?
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'I used column A.

.Range(.Cells(FirstRow, "C"), .Cells(LastRow, "C")).FormulaR1C1 _
= .Cells(FirstRow, "C").FormulaR1C1

.Range(.Cells(FirstRow, "d"), .Cells(LastRow, "d")).FormulaR1C1 _
= .Cells(FirstRow, "d").FormulaR1C1

End With

End Sub




lh wrote:

I would like to have a macro to copy a range of formulas in row 2 down for
all lines of input in an adjacent range. For example:

Input Formula
Row 2 Cell X2 Cell Y2
Row 3
Row 4
Row 5

In input date in the range Row2 through Row 5. I want to copy the formulas
in Cells X2 and Y2 down for the other three lines of input.

Thanks for any help that you can provide.


--

Dave Peterson

lh

Dave,

This worked great.

Thanks.

Lori

"Dave Peterson" wrote:

Hmmm. What column gets the dates?

Option Explicit
Sub testme01()

Dim LastRow As Long
Dim FirstRow As Long

With ActiveSheet
FirstRow = 2 'headers in row 1?
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 'I used column A.

.Range(.Cells(FirstRow, "C"), .Cells(LastRow, "C")).FormulaR1C1 _
= .Cells(FirstRow, "C").FormulaR1C1

.Range(.Cells(FirstRow, "d"), .Cells(LastRow, "d")).FormulaR1C1 _
= .Cells(FirstRow, "d").FormulaR1C1

End With

End Sub




lh wrote:

I would like to have a macro to copy a range of formulas in row 2 down for
all lines of input in an adjacent range. For example:

Input Formula
Row 2 Cell X2 Cell Y2
Row 3
Row 4
Row 5

In input date in the range Row2 through Row 5. I want to copy the formulas
in Cells X2 and Y2 down for the other three lines of input.

Thanks for any help that you can provide.


--

Dave Peterson



All times are GMT +1. The time now is 10:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com