Results 1 to 5 of 5
  1. #1
    New Lounger
    Join Date
    Dec 2009
    Location
    Northampton,UK
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I've created a basic macro to format a selected range of cells with borders, how can I check the number of rows and columns in the selected range. I don't want to draw inside lines if there is only 1 row or 1 column.

    Thanks for your help

    - Moz

  2. #2
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Code:
    Dim lngRows as Long, lngCols as Long
    
    lngRows=Selection.Rows.Count    
    lngCols=Selection.Columns.Count
    From this you can determine what you need to do
    Andrew

  3. #3
    New Lounger
    Join Date
    Dec 2009
    Location
    Northampton,UK
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Andrew

  4. #4
    5 Star Lounger
    Join Date
    Oct 2001
    Location
    San Bernardino, California, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Moz, would you mind sharing the macro for doing borders within a range? I have been struggling with something similar and a peek at your code would help.

    Thanks

  5. #5
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Maybe not what you are after, but as an example
    The code below will put a Solid Thick Edge and Thin Inside line on the selected range

    Code:
    Sub DoBorders()
    
    With Selection
        .Borders(xlInsideVertical).Weight = xlThin
        .Borders(xlInsideHorizontal).Weight = xlThin
        .Borders(xlEdgeLeft).Weight = xlThick
        .Borders(xlEdgeRight).Weight = xlThick
        .Borders(xlEdgeTop).Weight = xlThick
        .Borders(xlEdgeBottom).Weight = xlThick
    End With
    
    End Sub
    Andrew

Posting Permissions

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