help Modifiy Code

trimmer69

Active Member
Joined
May 22, 2004
Messages
440
Office Version
  1. 2013
  2. 2007
Platform
  1. 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.

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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,141,715
Messages
5,708,032
Members
421,540
Latest member
quocbinh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top