Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
MayAnk__Rathi
Helper I
Helper I

Unable to auto drag down formulas & data validation rules

I have some formulas in row 21 & 22 of from column C to N & in corresponding cell of column b is for serial number.
I want to drag down all formulas & data validation rule automatically in row 23 & 24, 25 & 26, 27 & 28 and so on of same column whenever I put next serial number.
How to do it aitomatically.
I already have created macro code for it but unable to apply it. Macro code is below this line. Kindly help.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim sourceRow1 As Long: sourceRow1 = 21
Dim sourceRow2 As Long: sourceRow2 = 22
Dim newRow1 As Long, newRow2 As Long
Dim lastCol As Long, col As Long
Dim cell As Range

If Not Intersect(Target, Me.Columns("B")) Is Nothing Then
Application.EnableEvents = False

For Each cell In Intersect(Target, Me.Columns("B"))
If IsNumeric(cell.Value) And cell.Row >= 23 And cell.Row Mod 2 = 1 Then
newRow1 = cell.Row
newRow2 = newRow1 + 1
lastCol = Me.Cells(sourceRow1, Me.Columns.Count).End(xlToLeft).Column

For col = 3 To lastCol
' Copy formulas from row 21 → current
If Me.Cells(sourceRow1, col).HasFormula Then
Me.Cells(newRow1, col).Formula = Me.Cells(sourceRow1, col).Formula
End If
If Me.Cells(sourceRow2, col).HasFormula Then
Me.Cells(newRow2, col).Formula = Me.Cells(sourceRow2, col).Formula
End If

' Copy drop-downs from row 21/22
On Error Resume Next
If Me.Cells(sourceRow1, col).Validation.Type <> -1 Then
With Me.Cells(sourceRow1, col).Validation
Me.Cells(newRow1, col).Validation.Delete
Me.Cells(newRow1, col).Validation.Add Type:=.Type, _
AlertStyle:=.AlertStyle, _
Operator:=.Operator, _
Formula1:=.Formula1, _
Formula2:=.Formula2
End With
End If
If Me.Cells(sourceRow2, col).Validation.Type <> -1 Then
With Me.Cells(sourceRow2, col).Validation
Me.Cells(newRow2, col).Validation.Delete
Me.Cells(newRow2, col).Validation.Add Type:=.Type, _
AlertStyle:=.AlertStyle, _
Operator:=.Operator, _
Formula1:=.Formula1, _
Formula2:=.Formula2
End With
End If
On Error GoTo 0
Next col
End If
Next cell

Application.EnableEvents = True
End If
End Sub

3 REPLIES 3
v-pnaroju-msft
Community Support
Community Support

Thankyou, @amitchandak, for your response.

Hi MayAnk__Rathi,

Thank you for contacting the Microsoft Fabric Community Forum.

From your question, we understand that you want to automatically drag formulas and data validation rules in Excel using VBA when new serial numbers are added. We appreciate your detailed explanation and code, but your question is about Excel automation with VBA.

This forum mainly focuses on Microsoft Fabric topics like Power BI, Dataflows, Data Pipelines, and other Fabric services. Excel-related questions, especially about VBA macros, are best answered in the Microsoft Excel Community. There, experts specialize in Excel automation and can help improve your macro or suggest other solutions for your needs.

Please post your question in the Excel Community. You can find the link here: Excel | Microsoft Community Hub

If you find our reply helpful, please mark it as the accepted solution and give kudos. This will help other members with similar questions.

If you have more questions, feel free to ask the Microsoft Fabric community.

Thank you.

amitchandak
Super User
Super User

@MayAnk__Rathi , Are you trying that in excel? I doubt we can do that in Power BI

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Yes, in excel

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors