ColourfulFigsnDiags
Chemical
- Aug 29, 2005
- 144
Just thought I'd pass on this little bit of code I wrote this morning (it is nothing fancy)- it may or may not be helpful for others, but it certainly was for me!
I have a spreadsheet which lists the contents of boxes. I wanted to put a separating line (thick black line) on the row where one boxes contents ended, and the next ones began.
Problem was I had 35,000 lines of contents- to do this manually probably would have taken a while
Anyway, here is some basic code to do it in 10 seconds...
Read the Eng-Tips Site Policies at FAQ731-376
I have a spreadsheet which lists the contents of boxes. I wanted to put a separating line (thick black line) on the row where one boxes contents ended, and the next ones began.
Problem was I had 35,000 lines of contents- to do this manually probably would have taken a while
Anyway, here is some basic code to do it in 10 seconds...
Code:
Sub format-row()
' Format row with thick black line whenever the box number changes ...
' loop over all rows
For i = 1 To 35001
' get the previous box number
pbox = Range("B" & i).Value
'get the current box number
cbox = Range("B" & i + 1).Value
'if the two are not the same, then we have gone to a new box
If (pbox <> cbox) Then
'therefore format row with a thick black line
Rows(i & ":" & i).Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End If
Next i
End Sub
Read the Eng-Tips Site Policies at FAQ731-376