Adding borders on the fly

dualhcsniatpac

Board Regular
Joined
Feb 18, 2009
Messages
126
Is there an easy way to write the code to add borders with out doing it all drawn out like I have below

Code:
.......
 
With ActiveCell.Offset(0, 1)
    .Borders
    .LineStyle = xlContinuous
    .ColorIndex = xlAutomatic
    .Weight = xlThin
End With 
With ActiveCell.Offset(0, 2)
 
and so on........

I was thinkint that there is probably a loop that I can run to add the borders. Basically what I want is when I add a row of data, have thin borders put on it.

Thanks in advance
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
This is what I have so far. I dont know if it is going to work

Code:
For i = 1 to 18
    ActiveCell.Offset(0, i).Borders
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
Next i

Another thing. Is there a way that I can make a string of certain numbers [1,2,3,6,7,9,10] and have the loop run through those numbers ONLY?
 
Upvote 0
Well for the first part perhaps something like this.
Code:
With ActiveCell.Resize(,18).Borders
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
 End With
Not sure about the 2nd part - how are you determing the numbers?

PS I'm pretty sure you've not posted all your code.

If you were to, and an explanation of it's purpose, then there is probably more chance that we can offer help.:)
 
Upvote 0
Perhaps

Code:
Sub test()
Dim x As Variant, i As Long
x = Array(1, 2, 3, 6, 7, 9, 10)
For i = LBound(x) To UBound(x)
    With Range("B" & x(i)).Borders
        .LineStyle = xlContinuous
    End With
Next i
End Sub
 
Upvote 0
Code:
        ActiveCell.Value = Now()
        ActiveCell.Offset(0, 1) = todaysdate.Value
        ActiveCell.Offset(0, 2) = coverunit.Value
        ActiveCell.Offset(0, 3).NumberFormat = "mm/dd"
        ActiveCell.Offset(0, 3).Value = coverdate1.Value & "/" & Coverdate2.Value
        ActiveCell.Offset(0, 4) = covertime.Value
        ActiveCell.Offset(0, 5) = juliandate.Value
        ActiveCell.Offset(0, 6) = juliantime.Value
        
        If tacknone.Value = True Then
            ActiveCell.Offset(0, 7).Value = 1
        Else
            ActiveCell.Offset(0, 7).Value = 0
        End If
        
        If tack1.Value = True Then
            ActiveCell.Offset(0, 8).Value = 1
        Else
            ActiveCell.Offset(0, 8).Value = 0
        End If
        
        If tack2.Value = True Then
            ActiveCell.Offset(0, 9).Value = 1
        Else
            ActiveCell.Offset(0, 9).Value = 0
        End If
        
        If tack3.Value = True Then
            ActiveCell.Offset(0, 10).Value = 1
        Else
            ActiveCell.Offset(0, 10).Value = 0
        End If
        
        If tack4.Value = True Then
            ActiveCell.Offset(0, 11).Value = 1
        Else
            ActiveCell.Offset(0, 11).Value = 0
        End If
        
        ' EB Welder outputs
        ''''''''''''''
        If Yellow0.Value = True Then
            ActiveCell.Offset(0, 12).Value = 0
        End If
        If Yellow1.Value = True Then
            ActiveCell.Offset(0, 12).Value = 1
        End If
        If Yellow2.Value = True Then
            ActiveCell.Offset(0, 12).Value = 2
        End If
        If Yellow3.Value = True Then
            ActiveCell.Offset(0, 12).Value = 3
        End If
        ''''''''''''''
        If Blue0.Value = True Then
            ActiveCell.Offset(0, 13).Value = 0
        End If
        If Blue1.Value = True Then
            ActiveCell.Offset(0, 13).Value = 1
        End If
        If Blue2.Value = True Then
            ActiveCell.Offset(0, 13).Value = 2
        End If
        If Blue3.Value = True Then
            ActiveCell.Offset(0, 13).Value = 3
        End If
        ''''''''''''''
        If Orange0.Value = True Then
            ActiveCell.Offset(0, 14).Value = 0
        End If
        If Orange1.Value = True Then
            ActiveCell.Offset(0, 14).Value = 1
        End If
        If Orange2.Value = True Then
            ActiveCell.Offset(0, 14).Value = 2
        End If
        If Orange3.Value = True Then
            ActiveCell.Offset(0, 14).Value = 3
        End If
        '''''''''''''
        If Violet0.Value = True Then
            ActiveCell.Offset(0, 15).Value = 0
        End If
        If Violet1.Value = True Then
            ActiveCell.Offset(0, 15).Value = 1
        End If
        If Violet2.Value = True Then
            ActiveCell.Offset(0, 15).Value = 2
        End If
        If Violet3.Value = True Then
            ActiveCell.Offset(0, 15).Value = 3
        End If
        If mass1.Value = True Then
            ActiveCell.Offset(0, 17).Value = 1
        End If
        If mass2.Value = True Then
            ActiveCell.Offset(0, 17).Value = 2
        End If
        If mass3.Value = True Then
            ActiveCell.Offset(0, 17).Value = 3
        End If
        If mass5.Value = True Then
            ActiveCell.Offset(0, 17).Value = 5
        End If
       
        ActiveCell.Offset(0, 16) = pumpcolor.Value
        ActiveCell.Offset(0, 18) = typeofdefect.Value
        
    ActiveWorkbook.Close True
            
    Call UserForm_Initialize
        
End Sub
As you can see I have so many places where I would have to individually enter the code to put on the borders so I was just trying to get it to go through a loop or something and add the borders in. So basically what I would like is for the borders to get put in every time I hit submit. (This code is under my submit button)

The numbers I picked were random. There are certain columns that I wanted to have a Medium side border thats what that was for.

Thanks again for your help
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

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