How to Dynamically fill the borders in excel

I have used vba code to fill the borders in excel and I have assigned a variable to the Range but it is showing an error. Is there a way where we can dynamically add borders in excel


Can you send the screenshot of error?


Hello @Jyothi_SUVERA
Try this VBA code

Function ApplyCellBorderActiveCells(sheetName As String) As String
    On Error GoTo ErrorHandler
    For Each cell In Sheets(sheetName).UsedRange
        If cell.Text = vbNullString Then GoTo SkipCell
        With cell.Borders
            .LineStyle = xlContinuous
            .Color = xlBlack
        End With
    Next cell
    ApplyCellBorderActiveCells = "Success"
    Exit Function
    Debug.Print Err.Description
    ApplyCellBorderActiveCells = "Error: " & Err.Description
End Function