• Check size of selected range in VBA macro

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Check size of selected range in VBA macro

    Author
    Topic
    #470935

    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

    Viewing 3 reply threads
    Author
    Replies
    • #1238554

      [Code]
      Dim lngRows as Long, lngCols as Long

      lngRows=Selection.Rows.Count
      lngCols=Selection.Columns.Count
      [/code]

      From this you can determine what you need to do

    • #1238560

      Thanks Andrew

    • #1238940

      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

    • #1239025

      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
      
    Viewing 3 reply threads
    Reply To: Check size of selected range in VBA macro

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: