Solved: Range Copy problem
I've constructed a formula. I put this formula in a cell and then attempt to copy it to a large number of cells via various Range copy techniques. I can get none to work. All are complaining about various object errors. The attempts at copy were commented out AFTER I tried and failed with them.[vba] Cells(lastRow + 7, 2) = formRank
'
' Copy this formula
'
'Worksheets(rankSheet.Name).Range(Cells(lastRow + 7, 2)).Select
'Selection.Copy
'Worksheets(rankSheet.Name).Range(Cells(lastRow + 7, 2), _
Cells(lastRow + lastRow + 7, col)).Select
'Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
'ActiveSheet.Range(Cells(lastRow + 7, 2)).Select
'Selection.Copy
'ActiveSheet.Range(Cells(lastRow + 7, 2), _
' Cells(lastRow + lastRow + 7, col)).Select
'ActiveSheet.Range(Cells(lastRow + 7, 2)).Formula = _
' ActiveSheet.Range(Cells(lastRow + 7, 2), _
' Cells(lastRow + lastRow + 7, col)).Formula
'Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=False
'rankSheet.Range(Cells(lastRow + 7, 2)).Copy _
' Destination:=rankSheet.Range(Cells(lastRow + 7, 2), Cells(lastRow + lastRow + 7, col))
'ActiveWorkbook.Worksheets(rankSheet.Name). _
' Range(Cells(lastRow + 7, 2)).Copy _
' Destination:=rankSheet.Range(Cells(lastRow + 7, 2), _
' Cells(lastRow + lastRow + 7, col))
[/vba]
I've done something very similar in another macro, but I just can't get this one to work.
Any ideas?
I do not understand your suggestion
You said:
[vba]ranksheet.Cells(lastRow + 7, 2)[/vba] I am confused because this only refers to a single cell, and the objective is to make 33 rows of cells contain this formula. I think there are 31 colums, so this would be 31x33 cells.
The thing that's confusing me again is that I have VERY similar code in another macro and it inserts a formula using a starting rangle with only one cell reference. The second reference uses two cell references, and it works.
I also got this to work as stated in my last post, but I have no clue whatsoever why my original attempt and many others failed. My original code placed the formula in a cell and then did a "paste special" to copy this cell to the entire range. I can see that this technique is probably much more efficient and more compactly stated.