Hello
I am looking for VBA to copy the first row in a named range and paste it to whole of the named range.
I am sure its very easy but I cant find anything.
Thank you
tttommy2
Sub PasteToWholeNamedRange()
Dim R As Range
Set R = Range("myRng") ' <-- put the name of your range between the quote marks
R.Rows(1).Copy R
End Sub
This pastes formulas only - retaining the initial format of each row in the named range.Thank you Joe - that was quick.
I should have been more precise. I would like to copy paste formulae from first row of named range to whole of the named range. I don't want to copy the formats.
tttommy2
Sub PasteToWholeNamedRange()
Dim R As Range
Set R = Range("myRng") ' <-- put the name of your range between the quote marks
R.Rows(1).Copy
R.PasteSpecial xlPasteFormulas
Application.CutCopyMode = False
End Sub
What exactly "does not seem to work" - do you get an error or ....? Can you tell me what the layout of your named range is? And can you post the single-cell array formula?Sub PasteToWholeNamedRange()
Dim R As Range
Set R = Range("myRng") ' <-- put the name of your range between the quote marks
R.Rows(1).Copy
R.PasteSpecial xlPasteFormulas
Application.CutCopyMode = False
End Sub
Hi Joe
Thank you for your reply.
I am having a problem with your last VBA code above. The first row of my named range contains a single cell array formula and your VBA code does not seem to work with it. When I take out the array formula your VBA code works a treat.
My array formula is single cell formula and is not part of an array. When I do an ordinary copy paste, it copies fine.
Any ideas?
Thank you for your help.
tttommy2
Sub PasteToWholeNamedRange()
Dim R As Range
Set R = Range("aData")
R.Rows(1).Copy R
'Add some code to format rows of aData after the first as desired
'Maybe
R.Rows("2:" & R.Rows.Count).ClearFormats
End Sub