Jed Shields
Active Member
- Joined
- Sep 7, 2011
- Messages
- 283
- Office Version
- 365
- Platform
- Windows
Hi guys,
I posted a question recently trying to use a standard formula based on a variable workbook name. The INDIRECT solution suggested worked fine until I realised that I'd need to have the additional workbooks open in order to return the results.
http://www.mrexcel.com/forum/showthread.php?t=580091
The reason I wanted to use a standard formula was so that I could use a piece of code I've written that would simply copy the formula from one cell and paste it accross and down for all cells within a range of rows and columns. Seeing as the formula now needs to be unique per column I need to change the code to copy the entire row of formula down instead of the one formula down and across. Here's my original code that copies a formula from B2 and pastes it down to the last row and across to the last column:
What I assume I need is to change the Range("B2") in the last line to Range("B2:???"), where ??? is the last column eg AA2. I'm not sure how to do this dynamically though. Any ideas ...?
I posted a question recently trying to use a standard formula based on a variable workbook name. The INDIRECT solution suggested worked fine until I realised that I'd need to have the additional workbooks open in order to return the results.
http://www.mrexcel.com/forum/showthread.php?t=580091
The reason I wanted to use a standard formula was so that I could use a piece of code I've written that would simply copy the formula from one cell and paste it accross and down for all cells within a range of rows and columns. Seeing as the formula now needs to be unique per column I need to change the code to copy the entire row of formula down instead of the one formula down and across. Here's my original code that copies a formula from B2 and pastes it down to the last row and across to the last column:
Code:
[FONT=Arial][SIZE=2]Sub CopyFormulaDown()[/SIZE][/FONT]
[FONT=Arial][SIZE=2]Dim lngLastrow As Long
Dim rngTargetStart As Range
Dim rngTargetEnd As Range[/SIZE][/FONT]
[FONT=Arial][SIZE=2]lngLastrow = Sheet3.Range("A65526").End(xlUp).Cells(1, 1).Row
lngLastcol = Sheet3.Cells(1, Sheet3.Columns.Count).End(xlToLeft).Column[/SIZE][/FONT]
[FONT=Arial][SIZE=2] Set rngTargetStart = Sheet3.Range("B2")
Set rngTargetEnd = Sheet3.Cells(lngLastrow, [FONT=Arial][SIZE=2]lngLastcol[/SIZE][/FONT])
Sheet3.Range("B2").Copy Range(rngTargetStart, rngTargetEnd)
[/SIZE][/FONT][FONT=Arial][SIZE=2]End Sub[/SIZE][/FONT]