Bottom Lines

adamsm

Active Member
Joined
Apr 20, 2010
Messages
444
The following code inserts bottom lines from row 6 onwards depending upon data in column C.

Code:
<dl class="codebox"><dd><code>Sub InsertBottomLine()
Dim LastRow As Long
Dim I As Integer
    Application.ScreenUpdating = False
    LastRow = Range("C" & Rows.Count).End(xlUp).Row
    For I = 16 To LastRow
        If Cells(I, 3) <> Empty Then Cells(I, 3).Resize(1, 8).Borders(xlEdgeBottom).LineStyle = xlContinuous
    Next I
    Application.ScreenUpdating = True
End Sub</code></dd></dl>
How could I make the code so that it inserts bottom lines from column C to column J if data consists in column F.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
Sub InsertBottomLine()
Dim LastRow As Long
Dim I As Integer
    Application.ScreenUpdating = False
    LastRow = Range([COLOR="Red"]"F"[/COLOR] & Rows.Count).End(xlUp).Row
    For I = 16 To LastRow
        If Cells(I, [COLOR="Red"]"F"[/COLOR]) <> [COLOR="Red"]""[/COLOR] Then Cells(I, 3).Resize(1, 8).Borders(xlEdgeBottom).LineStyle = xlContinuous
    Next I
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for the help. But your code only inserts bottom lines where data contains in column F but not in column C.

How could I overcome this?
 
Upvote 0
Code:
Sub InsertBottomLine()
Dim LastRow As Long
Dim I As Integer
    Application.ScreenUpdating = False
    LastRow = Range("C:F").Find("*", , xlValues, , xlByRows, xlPrevious).Row
    For I = 16 To LastRow
        If Cells(I, "C") <> "" Or Cells(I, "F") <> "" Then Cells(I, 3).Resize(1, 8).Borders(xlEdgeBottom).LineStyle = xlContinuous
    Next I
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for the help. The code now does what had been requested. How could the code be further enhanced so that it does not insert bottom lines if data only consits in column C. Meaning if column C has data and if column F has no data the code would not insert any line.

Any help on this would be kindly appreciated.
 
Upvote 0
Thanks for the reply. But with the modification the code does not seem to inert any lines. What may be the reason for this?

Here's the final code.
Code:
Sub InsertBottomLine()
Dim LastRow As Long
Dim I As Integer
    Application.ScreenUpdating = False
    LastRow = Range("C:F").Find("*", , xlValues, , xlByRows, xlPrevious).Row
    For I = 16 To LastRow
        If Cells(I, "C") <> "" And Cells(I, "F") <> "" Then Cells(I, 3).Resize(1, 8).Borders(xlEdgeBottom).LineStyle = xlContinuous
    Next I
    Application.ScreenUpdating = True
End Sub

Any help on this would be kindly appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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
Back
Top