FROGGER24
Well-known Member
- Joined
- May 22, 2004
- Messages
- 704
- Office Version
- 2013
- 2010
- Platform
- Windows
I have this code that Greg Truby provided several months back and now I would like to modify since the application has changed some.
My Original request was to copy formula from entire row above if column B was populated. The code perfectly.
My present need is to modify it so that it looks at column A and will allow me to paste in as many as 400 rows of data and still copy the formula down from row above to all 400 rows. I will also need to copy the data validation boxs down from the row above which the current code does not do. The range of data is A2:DR which I currently have to drag valaditon box down.
My Original request was to copy formula from entire row above if column B was populated. The code perfectly.
My present need is to modify it so that it looks at column A and will allow me to paste in as many as 400 rows of data and still copy the formula down from row above to all 400 rows. I will also need to copy the data validation boxs down from the row above which the current code does not do. The range of data is A2:DR which I currently have to drag valaditon box down.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' code by Greg Truby
' If not column B or more than one cell being changed, leave.
If Target.Column <> 2 _
Or Target.Count > 1 Then Exit Sub
Dim rngFormulasOverMyHead As Range, rngCell As Range
' Copy formulas from row above into current row.
On Error Resume Next
Set rngFormulasOverMyHead = Target.Offset(-1).EntireRow.SpecialCells(xlCellTypeFormulas, 23)
If rngFormulasOverMyHead Is Nothing Then
MsgBox "Formulas not found in row above.", vbInformation, "No formulas copied"
Exit Sub
End If
Application.EnableEvents = False
For Each rngCell In rngFormulasOverMyHead.Cells
rngCell.Copy rngCell.Offset(1)
Next rngCell
Application.EnableEvents = True
Set rngFormulasOverMyHead = Nothing
Set rngCell = Nothing
End Sub