+ Reply to Thread
Results 1 to 4 of 4

Cell Borders

Hybrid View

  1. #1
    Registered User
    Join Date
    08-27-2008
    Location
    California
    Posts
    8

    Cell Borders

    So I have the following code written. What kind of For statement can be written to make this work for a cell range. Eventually the code will make each cell a different color border. I also want it to skip over empty cells.



    If Application.WorksheetFunction.IsText(Range("C5")) Then
       Range("C5:E5").Select
       Selection.Borders(xlDiagonalDown).LineStyle = xlNone
       Selection.Borders(xlDiagonalUp).LineStyle = xlNone
       With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThick
            .ColorIndex = 6
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThick
            .ColorIndex = 6
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThick
            .ColorIndex = 6
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThick
            .ColorIndex = 6
        End With
        
    End If
    Last edited by rylo; 09-11-2008 at 11:37 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Can you please review the forum rules about wrapping your code. I've edited your post for you this time.

    See if this gets you started. You don't say how you intend to change the color for each iteration.

    Sub bbb()
      For i = 5 To Cells(Rows.Count, "C").End(xlUp).Row
        If Application.WorksheetFunction.IsText(Cells(i, "C")) Then
          With Cells(i, "C").Resize(1, 3)
            .Borders(xlDiagonalDown).LineStyle = xlNone
            .Borders(xlDiagonalUp).LineStyle = xlNone
            With .Borders(xlEdgeLeft)
              .LineStyle = xlContinuous
              .Weight = xlThick
              .ColorIndex = 6
            End With
            With .Borders(xlEdgeTop)
              .LineStyle = xlContinuous
              .Weight = xlThick
              .ColorIndex = 6
            End With
            With .Borders(xlEdgeBottom)
              .LineStyle = xlContinuous
              .Weight = xlThick
              .ColorIndex = 6
            End With
            With .Borders(xlEdgeRight)
              .LineStyle = xlContinuous
              .Weight = xlThick
              .ColorIndex = 6
            End With
          End With
        End If
      Next i
    
    End Sub
    rylo

  3. #3
    Registered User
    Join Date
    02-20-2009
    Location
    La, CA
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Cell Borders

    hello

    what if we didn't know the number of rows ?

    could you plz tell me how to modifiy this code to make it work with n rows

    regards

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Cell Borders

    When using loops you must have some method of determing when to stop the loop.

    In Rylo's code it loops from row 5 to the last row that has an entry in column C

    i.e. if the last entry in column c is row 100 then it will loop rows 5 to 100

    For i = 5 To Cells(Rows.Count, "C").End(xlUp).Row
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Protected Formulas
    By georgeeasten in forum Excel General
    Replies: 13
    Last Post: 12-10-2018, 12:47 AM
  2. make it so text transcends cell borders
    By mufan in forum Excel General
    Replies: 1
    Last Post: 08-11-2008, 02:12 PM
  3. Cell linked to a "wandering" cell
    By BigKahuna in forum Excel General
    Replies: 1
    Last Post: 02-29-2008, 12:27 PM
  4. Trouble with Excel Formula?
    By Beev in forum Excel General
    Replies: 4
    Last Post: 05-10-2007, 04:26 PM
  5. Pulling a worksheet name from cell value (custom function needing help)
    By Kurisu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2006, 09:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1