How to draw the line by macro?

Hi,
 I have one excel file which has Detail tab. It has Total Amount column. Now i need to draw the line if the first few row total becomes more than 50000. I need to draw the line on that Raw where sum of Total Amount > 50000.

Is there any way by conditional formatting or by macro?Example_Drawline.xlsx
Share PointAsked:
Who is Participating?
 
Subodh Tiwari (Neeraj)Connect With a Mentor Excel & VBA ExpertCommented:
You may try something like this...
Sub DrawLine()
Dim lr As Long, i As Long
Dim Total As Double

lr = Cells(Rows.Count, 3).End(xlUp).Row
For i = 2 To lr
    Range("A" & i & ":C" & i).Borders(xlEdgeBottom).LineStyle = xlNone
Next i
For i = 2 To lr
    Total = Total + Cells(i, 3)
    If Total > 50000 Then
        With Range("A" & i & ":C" & i).Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThick
            .Color = RGB(246, 174, 132)
        End With
        Exit Sub
    End If
Next i
End Sub

Open in new window

Example_Drawline.xlsm
0
 
Share PointAuthor Commented:
Thanks a lot Neeraj. That's  what i was looking for.
0
 
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.